« first day (3528 days earlier)      last day (1405 days later) » 
00:00 - 16:0016:00 - 22:00

12:17 AM
Hey, looking for a quick tip. Python noob here.
Trying to get a program running: https://github.com/littlemountainman/modeld/blob/master/minimal.py
There is an import which is not working: from tools.lib.parser import parser
And I can't figure out why. It just says: ModuleNotFoundError: No module named 'tools.lib.parser'
But the line above works the same way: from tools.lib.framereader import FrameReader
What am I missing here?
 
12:58 AM
did you run pip3 install -r requirements.txt
 
1:09 AM
yes :) all worked fine ... just don't get why this local library is not found
 
can you use .replace in a variable?
 
@aaa28 what do you mean? where?
 
well its ok now, I just missed soemthing
 
user11867287
1:29 AM
How hasn't anyone taken this over?
 
1:39 AM
are there any interesting active developer chats except here? looking through this, they just want you to ask questions and then close the questions as "not specific" or against the "terms" I just want a place where I can discuss problems and have open discussion with other devs
 
2:03 AM
@MisterMiyagi As someone who came from a language which required indentation (cough COBOL) and didn't use brackets - you can just point them to the off-side rule. Honestly, learning Java after scripting, BASIC, and COBOL was rough (brackets still look weird to me but I've learned to accept it)
I don't know why COBOL and Basic are not in that article - indentation mattered a ton in those languages
@ArthurCollé In python? feel free - we talk about a lot of languages and concepts here (and have a lot of asynchronous conversations due to time zones) but focus on Python (hence, python room). There are also a lot of close vote and other pointer to main but spend some time on a pandas or NLP tag and you will know why. (there is also a lot of knowledge in this room - I'm a 15 year IS veteran and I still get dwarfed in knowledge regularily)
 
does anyone have spare time, i dont know what im doing here, thanks bpa.st/XYUQ
 
2:18 AM
@GaryOak no, there was suppose to be a team assigned to it but well....corvid & a few other issues pushed back (presumably it will be assigned to some group but I cannot guarantee this)
Though I do know there was a paper published this year on face shifting by the MS research team (there is a free arxiv pre-print) so that's encouraging
 
2:59 AM
How can I find all the substrings that are between a single bracket on both sides, no double or triple brackets like this code does:
re.findall(r"\(.*?\)", l)
 
I am writing something to a text file using values from a list, how would I put new line in each line, here is my code bpa.st/QRDA
 
 
1 hour later…
4:22 AM
@AnnZen since you don't show what l is, it's harder to help you. However, this might help:
>>> import re
>>> re.findall(r"\(.*?\)", '(((foo)))')
['(((foo)']
>>> re.findall(r"\([^(].*?\)", '(((foo)))')
['(foo)']
>>> re.findall(r"\((?!\().*?\)", '(((foo)))')
['(foo)']
In the future you want to provide people who are helping you with code they can copy and paste into an interpreter and immediately begin tweaking it to help you.
 
l = '(M264/M274)+(((551/882)+362/(362/551/882)+889)/((551/882)+362/(362/551/882)+889)+(241/242/275/550/551+882/889/362))'
I want to retrieve a list:
 [(M264/M274), (362/551/882), (362/551/882)]
Is this supposed to work
re.findall(r"[^\(.](\([^\(.].*?[^\).]\))[^\).]", l)
 
 
1 hour later…
5:52 AM
how to return to list from a function, and use that said lists in other function?
 
6:05 AM
@aaa28 what is your current function? You've asked quite a few questions over night (in Euro time, at least) and it seems your code is evolving. Where are you up to now?
 
6:16 AM
@NoelSchenk where are you using from tools.lib.parser import parser? In the code you've linked, that import doesn't exist but are you suggesting that the import fails if you put it directly below from tools.lib.framereader import FrameReader or is the import in some other file?
 
@roganjosh well in my function I am using with open(textfile, 'r') as text_file: where textfile is a variable, that will come from another function or will be define outside the function
 
Ok, so you'll pass textfile as an argument when you call the function and then return something_here from the function. You'll need to assign that returned value to a name. I'm aware that this description might not clarify anything for you but you haven't given an example for me to work with
 
this is the function I am having trouble with bpa.st/PJNQ
 
Before moving on, I'm not sure I follow how that function is intended to work
for d in list_1:
    if z in list_1:
The if check only needs to be run once, doesn't it?
kk = list_1.index(z) will only ever give you the index of the first occurrence, not to mention that it's outside of your loops, so list_1[kk] = z just keeps referencing the same index
 
6:37 AM
the function will try to get an index from and input, then retrieve the corresponding element from a list based on the index. Then if a condition met it will modify the retrieved element, and write it again on the text_source
i hope it make sense
 
But presumably the for loop means that you want to change all occurrences of the value in list_1?
 
yes, correct in able to write the content in the correct position I need to write everything, cause 'a' mode, just append the content at the end
lets say a line, maybe in the third line, from the text_file is "banana", "0" and I wanted to change it to "banana", "1"
 
Ok, but what happens if line 5 is also "banana", "0"? Should that line also be updated?
 
the items in the text file should be unique, so Im not thinking about duplicate
 
6:57 AM
This makes more sense to me for what you're trying to do
 
ok I will try it, but I already have an open file for reading in other function, is it ok to use another in this function
 
Your current outer for loop just keeps doing the same thing n times. Since you have unique values, you need only do that once
@aaa28 not really. And unless you're using threads et al. I'm not sure why you'd have a file open in another function anyway
 
@roganjosh Meh, don't take it too hard. It's the internet, either we chose to take things the wrong way or we don't. I regularly feel like some evil, smug hardass when prodding people to work out things themselves instead of giving da codez, if that's some consolation. In this case I was just surprised that something so fundamental seems not to have a proper introduction.
Oh, and I'll take that Ceremony of Absolution, if it's still available. Can i get fries with that?
 
<scurries off to gather the tealights> Sure!
@MisterMiyagi I didn't think you'd take it the wrong way but I've had frustrating dialogues on meta before. There was a case where I VTC'd a question and pointed the user to an answer in comments, but the comment got deleted. In that case, I felt like someone was meddling with my interpretation of how SO should first-and-foremost help people and, on reflection, I wondered whether I'd done the same to you in trivialising your desire to help in that particular situation. Ketchup with the fries? :P
 
7:24 AM
@roganjosh I tried your suggestion, thank you by the way , but it wont work with my other function, I am getting confused cause the parameters of that function the one we talk about came from two different function, I think the problem came from it, I test every variables and it have all the correct values, its just, the code wont go through, so I will still keep on looking, thanks again
 
@aaa28 you're welcome and it's great that you're going to investigate the problem. Keep in mind that I suspect something is wonky if you have file objects open in multiple functions - this feels to me, at least, like there is a deeper flaw to the design. If you find yourself at a dead end then I'm happy to help if you have a broader MCVE to cover the issues
Although, I've just remembered that you originally asked how to return things from functions. You're not using global are you, @aaa28?
 
@roganjosh I'm culturally more of a Rot-Weiß guy, so if you could pass also the mayonnaise with the ketchup...
 
yeah I have asked that the two list came from a function, it was not really supposed to return the list, but since I need it, I just returned it, and about the source_text, I have a function that opens it it goes like this with open(text_file, 'r') as f: new_text_file = f.readlines() return new_text_file
and text_file was defined outside of every other function its just like text_file = "some.txt"
 
The with context manager will automatically close the file for you once you leave the scope, so you're likely incorrect in assuming that you have open files in other functions
 
Im not sure I understand global is
 
7:35 AM
@aaa28 it's for the best :P But on a serious note, a lot of people appear to turn to that when they're unsure about how to return modified objects from functions, and it just causes more problems
 
oh I see, cause list_1 and list_2 is based on that, though in the problematic function, list_1 and list_2 still throw the correct elements
 
@MisterMiyagi mixing mayonnaise with ketchup cannot be used in a sentence that includes a reference to "culture". Gross!
@aaa28 "throw the correct elements"? I'm not following you, sorry
 
i mean the values, or the items thats inside the list
let says I created list_1 and list_2 on function 1, based on the lines from the text_file. then I used list_1 and list_2 in function 2, which is the one we are talking about earlier
opening text_file is in function 0, list_1 and list_2 is in function 1, and list to write/modify a text file is in function 2
 
You don't need a function that just opens files. It's totally reasonable to assume that you'd also want to read the contents, so it seems like function 0 and function 1 can be consolidated into a single function
 
@LinkBerest My views on that might be screwed up a little. I ferociously expect people to RTFM when they have a problem, but only that. There is so much junk out there on the internet, unless people know the solution already they cannot tell what is a proper reading material. For something as fundamental as indentation, I'm very surprised The Fabulous Manual seems not to cover it properly.
 
7:48 AM
"indentation" gets an honourable mention as a bullet point in the official tutorial under the technical heading of "Whetting Your Appetite"
 
@AnnZen You just have to exclude seeing another opening brace before the closing close. re.findall(r"\([^(]*?\)", l) works.
Note that regular expressions are not really suitable to parse opening/closing pairs, outside of very simple cases. (Yours actually being one)
 
@MisterMiyagi that finds more than the 3 desired matches though
>>> re.findall(r'(?<!\()\([^()]*\)(?!\))', l)
['(M264/M274)', '(362/551/882)', '(362/551/882)']
^ readable af
 
gotta love regex notation ^^
it's moments like these that remind me why I've done a lot more parsing work since discovering pyparsing...
 
8:13 AM
cbg patch
just was learning how to do testing and I was wondering if theres a nice way to kind do testing like they do in j-unit stackoverflow.com/questions/7455931/…
 
@roganjosh at line 52 parsed["lll"] . I think it should be implemented the same way as here github.com/littlemountainman/modeld/blob/master/main.py
 
looks a lot like python decorators so i figure there's a pretty pipeline similar to junit
 
@NoelSchenk ok, but I was asking specifically about the import that you said wasn't working
 
@Skyler AFAIK unittest is modelled after J-Unit, but it does not use decorators.
Many people prefer pytest, as it has much less boilerplate.
 
@roganjosh I added the import myself like this: from tools.lib.parser import parser
 
8:17 AM
does it use some kind of similar annotation or you always have to manually assert
 
@NoelSchenk I understand that, but I was very specific in my question:
2 hours ago, by roganjosh
@NoelSchenk where are you using from tools.lib.parser import parser? In the code you've linked, that import doesn't exist but are you suggesting that the import fails if you put it directly below from tools.lib.framereader import FrameReader or is the import in some other file?
 
> The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages.
 
@roganjosh yes I put it directly below from tools.lib.framereader import FrameReader
 
@Skyler I'm not really familiar with JUnit, so I cannot say how annotations are used there. unittest works by inheritance (unittest.TestCase), naming convention (test_..., setUp, ... methods) and assertions (self.assertEquals, ...).
You may want to take a look at the documentation to see whether it is what you are looking for.
 
yea, just was reading there
 
8:22 AM
As mentioned, I strongly recommend to consider pytest as well
@NoelSchenk Can you please post the traceback of the error?
Such issues are often due to circular imports, which prevents loading the module.
The error message is then technically correct, though not that helpful for the unaware.
 
sure:
`
Traceback (most recent call last):
File "minimal.py", line 6, in <module>
from tools.lib.parser import parser
ModuleNotFoundError: No module named 'tools.lib.parser'
`
 
strikes "circular import" from the list
is your code version recent enough? tools.lib.parser was added end of march
 
I was going to download it to play with but I'm tethered to my phone and I've cancelled at 8MB. How big is the repo?
 
8:37 AM
bigger than 8MB
100.9 MB
 
Yeah, that eats too much into my ability to be a keyboard warrior so I'll pass
(suddenly conscious that YouTube random play is currently on Bonnie Tyler and my data usage priorities are completely messed up)
 
@MisterMiyagi yes there is a file called parser.py inside tools/lib it has also a def parser(outs):
 
@MisterMiyagi No, I don't. :( I thought indentation was adequately covered in the official tutorial, but it just gets a brief mention here, and the 1 space indentation in those examples is almost invisible in my browser (maybe it's monospaced in other browsers).
 
I see 4 spaces from mobile
 
It's also 4 spaces for me.
 
8:47 AM
But anyway, the official tutorial is aimed at people with some coding experience, it's not good for raw beginners. I just had a look at python indentation tutorial in Google. There's nothing I'd recommend on any of the results on the first page.
@MisterMiyagi Oh good. It's just this Samsung browser then.
 
@NoelSchenk Okay, I'm afraid we need some shotgun debugging, then. Might feel a bit random...
Can you please import tools.lib and print(tools.lib.__file__)? Check whether this points next to the parser.py
@PM2Ring I'm just wondering that there seems to be nothing that counts as explaining indentation. The parser producing INDENT/DEDENT tokens seems to be well beyond even intermediate level.
 
@MisterMiyagi oh no it point to another directory. Can I change that somehow?
 
@NoelSchenk Alright, that's a lead. It seems like the library cannot be installed, how do you mount it? Do you set PYTHONPATH?
 
@MisterMiyagi Agreed. Talking about INDENT/DEDENT tokens is definitely not newbie-friendly.
 
no that is all:
from common.transformations.camera import transform_img, eon_intrinsics
from common.transformations.model import medmodel_intrinsics
import numpy as np
from tqdm import tqdm
from tools.lib.framereader import FrameReader
import tools.lib
import matplotlib
import matplotlib.pyplot as plt
# imgs just a list of images as in YUV format

print(tools.lib.__file__)
 
8:54 AM
For the poor souls that are still hung up on the "Array versus Pointer" tangent: A recent Q exists about the topic. The answer pointing out that C knows lvalues and rvalues was helpful to me.
@NoelSchenk PYTHONPATH is an environment variable. You should be able to check it in your terminal, or by doing import os and print(os.environ['PYTHONPATH']) in Python.
 
(I'll shut up about indentation while you're busy helping Noel)
 
@MisterMiyagi ah yes I found it it points to the directory of the file where it cant find the parser. Why does it set it relative to this path? if I have multiple projects, they will use different libraries.
 
Python isn't doing that. PYTHONPATH is something that you should set to tell Python where to look for libraries. If you've followed some recipe or installation script, there's a good chance that this did set PYTHONPATH without you realising it.
You should re-define PYTHONPATH to point to the proper code location.
How to best do this depends a bit on your environment.
In bash, you basically just do export PYTHONPATH=<path to the library>. Some people put that in their .bashrc to have it on each login, or in some script that they explicitly source, or type it manually whenever they need it. It's a matter of preference.
 
@MisterMiyagi but if a project was developed in a way that it uses PYTHONPATH you have to change it on each fork that you use?
 
Kinda, yes. You set PYTHONPATH to say "use this code over there". So if you have several versions/forks of the code, you must ensure that PYTHONPATH points to the one you want to use.
Usually, you use a separate shell instance for each version, or have some script to quickly switch between them.
 
9:08 AM
@MisterMiyagi ah okay. That makes sense. Thank you so much for the help.
 
Hey guys.
Can happiness_points = map(int, input().split()) be used to take input in the following format?
1 3 2 4 5 6 9 1 0 1
Because print(happiness_points) prints something pretty weird
 
@d4rk4ng31 does it print something like <map at 0x111c78f90>?
 
Yes
What is that?
Address?
 
@PM2Ring I'd be happy if you'd resume afterwards.
@d4rk4ng31 It's the representation of a map object. That includes the address, but it is not the address.
 
Hmm... then what do I use here?
Because unpacking gives the correct result
 
9:12 AM
You probably meant to convert the map to a list, or iterate over it.
@d4rk4ng31 The real question should be "what is the correct result"? Having a map object instead of unpacking it forcefully often is desirable.
 
happiness_points = list(map(int, input().split()))
This works
Is this supposed to?
 
yes.
 
Ah... How does the conversion happen?
 
just keep in mind if you only want to iterate over the result, there is no need to convert it to a list.
@d4rk4ng31 list consumes the map iterable, just like it can consume any other iterable.
 
hmm... need to learn what is meant by "consuming" iterable. Thanks :)
 
9:35 AM
hmm, i seem to not be understanding something about how to structure unit tests
from Game import Game
import  unittest

class BowlingTest(unittest.TestCase):

    def SetUp(self):
        self.g = Game()

    def test_canRoll(self):
        self.g.roll(0)

if __name__ == '__main__':
    unittest.main()
in this example the canRoll test function doesnt think g exists despite the setUp
oh wow, nvm
cap on setUp
 
10:01 AM
The takeaway here is that snake_case is the one true way
corollary: pytest
 
recbg
 
recbg
 
Hello everyone! I had a question about Python packaging. So most open source Python projects I have come across, they have this "setup.py" file that helps with installation and owner information. So my question is when I should make use of this? Suppose if I am making a game with PyGame/Arcade, will this be a good place to use setup.py?
 
setup.py (and similar mechanisms) allow to easily install and distribute your package. Use it when you want (users) to be able to do pip install my_package and the like.
 
10:16 AM
Oh I see. Thanks :D
 
There's some history in the PEP for pyproject.toml python.org/dev/peps/pep-0518/#abstract
 
10:41 AM
too broad, thinly veiled homework dump stackoverflow.com/questions/62358500/…
and two bad, wrong answers, yay
 
TIL the Python room does cv-pls.
 
On occasion :)
 
typo, user missed to qualify name with module stackoverflow.com/questions/62358173/…
 
Yeah, I checked the room rules first, just to make sure you didn't accidentally paste into the wrong tab.
 
10:46 AM
Hehe, thanks
 
Methinks Cody might nest in the Python room this year :) Nice to have you around
 
He mingles with the lowlives to affirm the superiority of C++ people ;)
 
One moderator flag, and the dude never freakin' leaves. It's OK, you can say it.
One day, I will close the tab...
 
You are welcome though :P
 
Even if I do believe in the superiority of C++ people?
 
10:51 AM
Yes, we're an inclusive room, being wrong doesn't exclude you
7
 
Good to know. I have been wrong once or twice.
 
I hope that was mod-deleted ;D
 
Nah, self-censorship.
I would have agreed with it. :-)
 
Weird, though. I know what perl stands for but I've only ever seen Miyagi write it in caps
 
Officially, it's not an acronym. Maybe he's confusing it with PEARL?
 
10:54 AM
The only time I deal with PERL is when some other people's code breaks and I have to fix it. Shouting is involved. And swearing.
 
> from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was officially changed to Raku in October 2019.
Wow, I missed that!
 
"The Other 'P' Programing Language That Shall Not Be Named" was too long, I suppose.
@AndrasDeak Yeah, that was a whole thing for the SO tagging system. I remember it with a distinct lack of enthusiasm.
 
All-Caps PERL express my barely suppressed rage without being harmful to minors. I hope.
 
From the official announcement: "It can be used interchangeably with the original "Perl 6" name or even be combined with it to form "Raku Perl 6". Pick the one that works the best for you and use it consistently." Seriously, what? Pick a name and stick with it.
 
That's a very perl'y attitude. Kinda fitting.
 
10:56 AM
Heh. "We" should've renamed python 3 to "fishslap python 3 or whatever"
 
Makes sense that you would need a spark in order to explode.
 
@Yuva Please take a look at the room rules. We ask not to post fresh questions (<48h) here to avoid duplicate discussion.
 
oh ok. thanks.
 
11:14 AM
So what should we do about the lack of good, newbie-friendly info about indentation in the official docs? The PEP-8 stuff assumes you already understand how indentation works. Maybe @holdenweb has a suitable indentation tutorial that we could add to the SO Python wiki.
 
Indentation specifically for chat messages? It might be a lost cause... Formatting options in chat are not spectacular. Prefer using the main site to post questions that need more than a small amount of code.
 
I would prefer to see something in the official documentation (for reasons cited above) but have no idea how to approach that.
@CodyGray No, for Python source code. That braces thingy... ;)
 
@CodyGray nah, it's about it being a pillar of the Python language and yet we can't find any decent official reference for why it's important, for people new to the language
 
@PM2Ring dabeaz' newly published course mentions it a bit dabeaz-course.github.io/practical-python/Notes/01_Introduction/…
 
Well, isn't the bigger issue here that the official documentation, which includes a tutorial, isn't making this clear?
 
11:22 AM
@CodyGray As roganjosh said, how indentation works in Python is essential info, but it's not really covered well in a newbie-friendly fashion in the official docs.
3 hours ago, by PM 2Ring
But anyway, the official tutorial is aimed at people with some coding experience, it's not good for raw beginners. I just had a look at python indentation tutorial in Google. There's nothing I'd recommend on any of the results on the first page.
 
@CodyGray for that we have sopython.com/wiki/…
Anything with more than a bit of code is offloaded to pastebin et al.
 
While I don't entirely agree with Python's design decision to make whitespace significant, my understanding is that indentation in Python is supposed to be obvious. You indent constructs the same way you'd indent them in any language.
There's no mention in programming tutorials that you should spell words correctly in your comments, either. It's just kinda obvious.
 
I guess we could create a canonical Q&A for it, but it would be hard to make it fit that format. And SO really isn't suited to tutorial / documentation stuff. But it'd be good to have something to send newbies to, especially those who are trying to learn via videos & coding contests, etc, rather than working through a proper tutorial.
 
@CodyGray that was the reason that put me off of python for years. But then the upsides convinced me to try it and I haven't looked back.
And yes, using straightforward indentation works. The only subtlety I can think of is working non-straightforward indentation...
 
@PM2Ring "And SO really isn't suited to tutorial / documentation stuff." If only there was a... wait, wait, never mind. We tried that already.
 
11:27 AM
@PM2Ring I think it'd be too broad. You'd either have to cover everything like context managers or you'll just attract a whole bunch of "I indented code here and it did X but not Y"
 
RIP
@roganjosh and nobody who needs it will google "how to indent python"...
 
Well, that doesn't matter, if it's useful as a canonical dupe target. But I suspect it won't really be, and it gets a bit too close to a "RTFM" closure for my comfort.
 
What info are we missing from the official tutorial?
 
@AndrasDeak That looks good, but I think we need something a bit longer, just to drive the point home.
 
@roganjosh I guess technically it is just "How does Python define blocks?", but not sure if people would look for that
 
11:31 AM
@CodyGray Exactly. ;) FWIW, I also avoided learning Python for several years because I thought the whitespace thing was silly. I'd been coding for 30 years or so before I learned Python.
 
@AndrasDeak Basically everything beyond "indentation is important crickets"
 
@MisterMiyagi In my trip up and down the stairs, I was thinking about what we are trying to answer here. Are we just being sidetracked by this one particular instance? What do we actually want to convey about indentation to newcomers? Python is a starter language for many, so will they even have a concept of scope etc.?
 
If it were me, I'd roll it into a more comprehensive discussion of blocks. A lot of beginning programmers are lacking a firm understanding of how blocks/scoping works. Since indentation is what creates that in Python, it only makes sense to put it there.
 
@AndrasDeak It's not exactly newbie-friendly though. You're going to lose most of your audience when you start talking about INDENT / DEDENT tokens.
 
11:35 AM
But make the sentence or two that points out how significant indentation is in Python appear in bold, so programmers experienced in other languages will be less likely to miss it if they skip the whole section on scoping/blocks.
 
@roganjosh the official tutorial is not a new-to-programming tutorial
So question is if there are good newbie-aimed tutorials that cover this
 
But I get a feeling that the situation that MM raised is about a newcomer. That's why I'm trying to understand what we actually want to convey
I'm trying to cast my mind back 5 years to having no programming experience and I'm not sure I found the concept of indentation confusing. I'm really trying hard to think of some mental blocker I faced. I screwed things up all over, but I'm not sure that indentation as a "thing" confused me
 
We need to cater to 2 groups: absolute raw beginners, who don't even know what "code block" means, and people who have done some coding in other languages, and are having mental difficulties reading code that doesn't use braces to delimit blocks. (I guess we don't have to worry about Pascal coders, who delimit stuff with begin & end).
 
(Fortan, bash, MATLAB etc. also don't use braces)
 
@roganjosh I think it is not too difficult to handwave scoping and similar things into there, as long as one does not go the entire route of locals+closures+class+globals. "Function open a new scope, not blocks. Scope means that names defined inside mean different things than outside." could be enough.
 
11:45 AM
Handwaving sucks, though. It's like going from GCSE to A-Level Chemistry in the UK where the first lesson that you learn in A-Level is that everything you've learned about the structure of an atom is entirely wrong and just a simplification to not trouble your precious little brain
 
What I've seen so far are three cases: A) Newbies being confused at basic blocks being defined by consistent indentation. That's the classical for-loop with jagged indentation. B) OtherLangs being confused by dedenting. That's the "closing both nested if and containing for" when people are off-by-some. C) AnyOne confusing blocks with scopes.
@roganjosh Let's call it "teasing", then. I hope my example wasn't actually incorrect, just incomplete.
 
@CodyGray True. It wouldn't be useful as dupe target. When someone posts code that doesn't work because of borked indentation, we generally CV it as a typo. But it'd be good to have something you could link in a comment for those OPs.
 
@roganjosh lies-to-children
 
Minor facts
 
@MisterMiyagi My analogy was more extreme than what you're suggesting but I honestly hate things presented as fact to make things easier for newcomers to digest. If we want to present something to newcomers, it should be factually correct even if it only encompasses limited cases, and it should note that details are missing
The problem being; what do we expect newcomers to understand at the point at which you want to explain indentation
 
11:51 AM
@AndrasDeak Good point, especially bash. Fortran (& assembler) was fun back in the days of punched cards, but you could program the card punch to tab to the proper columns for the various fields.
 
@roganjosh As far as I am concerned, basically A and B, perhaps with C (because the equivalent of blocks in many languages does imply scope). Having several answers on scoping, I cannot recommend trying to explain it in full to a beginner. It's enough to know what "a scope" is, not which ones there are and how to link them.
Agreed though that it can easily be a slippery slope of confusing people with unexplained jargon, omitting important parts, or using incorrect language.
 
I have to disappear for a little bit for Saturday crossword club I'm afraid, rbrb for a bit
 
@roganjosh I think we should aim for something that raw beginners will understand. That thing by dabeaz that Andras linked earlier is good. It just needs a few more common examples, like basic for & while loops, plain if and if ... else, a function definition, a class definition, and a with open, and maybe a try... except. Even if total newbies don't fully understand the last three it would be handy for them to have examples to refer to.
@roganjosh rbrb
@MisterMiyagi I agree that scoping should only be mentioned briefly in passing. It's a separate topic because blocks in Python don't create a new scope.
 
12:07 PM
@Aran-Fey Thank you so much!
 
@AnnZen Rather than (1+n)*(n/2) you can use floor division. That way, the result is an integer, not a float. Eg, (1 + n) * n // 2
And it will correctly handle n that's too big to be (accurately) represented by a float.
 
How do I stop a generator function after it reaches a particular line in which it is looping through and pulling out values from?
 
@PM2Ring It won't be accurate
 
@jigglypuff If you're looping over the generator in a for loop, just break out of the loop.
 
@PM2Ring I'm doing the inverse, I've got a loop inside a generator
 
12:19 PM
@AnnZen Yes it will. Either n or (n + 1) must be even. The result of the division will be exact.
 
One solution is to trim the input to the right size before I give it to the generator function, but I thought that it's possible to halt the generator after it reaches some condition
 
@jigglypuff Can you show us a short example?
 
one sec
 
@PM2Ring my mistake, I thought // gets executed before *
 
def get_occupations() -> list:
    for line in open(OCCUPATIONS_FILE):
        tokens = line.split()
        if len(tokens) < 1 or "#" in line:
            continue
        if line == "# Stop reading here":
            break
        yield {"name": tokens[0], "occupation": tokens[1:]}
Then calling list(get_occupations())
Like I said, I can read the file beforehand, and then only pass to the function the parts before # Stop reading here. Is that my only option?
 
12:22 PM
@AnnZen No worries. Multiplication & division have the same precedence, and the evaluation proceeds from left to right, as usual.
 
@jigglypuff Can you clarify how this does not do what you want? it seems to match your problem statement.
 
@MisterMiyagi it doesn't stop, but keeps going and reads the rest of the file, pulling out occupations after the line # Stop reading here.
oops, my bad, theres a bug in that function.
 
ahem...
 
10 points to who ever spots it
 
Anyways, you have two problems. ' "#" in line' triggers, and line includes a trailing \n character.
 
12:27 PM
@jigglypuff Indeed. Your lines still have a \n at the end. Also, it's better to open the file using the with syntax.
 
@MisterMiyagi yes, that's it about the #, well done. I'll look at the \n problem.
with open(OCCUPATIONS_FILE) as f:
    lines = f.readlines()
for line in lines:
    ...
like this?
 
@jigglypuff Also, the if len(tokens) < 1 or "#" in line: continue stuff means that if line == "# Stop reading here": will never see a line containing a #
@jigglypuff Almost. The for loop has to be inside the with block. And get rid of that readlines!
 
Like this:
 
@ExoticBirdsMerchant :)
 
12:35 PM
with open(OCCUPATIONS_FILE) as f:
    for line in f:
 
@PM2Ring what the, I didn't know you could do that
would line still have a trailing \n?
 
@jigglypuff Yes it will. But you can use .strip or .rstrip to get rid of that. See docs.python.org/3/library/stdtypes.html#str.rstrip
 
I tried to close a question as duplicate, but they don't recognize this: stackoverflow.com/questions/62354860/…
 
12:51 PM
for line in f:
    line = line.strip()
    tokens = line.split()
    ...
I wish the last two lines could be combined into one, but it can't be because strings are immutable and .strip() returns a string.
 
@AnnZen Sorry, I don't understand. Which question are you trying to close? The link you posted is to an answer you wrote.
 
oh, so that's why
 
@jigglypuff No you don't. ;) You want to keep the stripped line so you can do that test to see if it matches "# Stop reading here"
 
but even after pasting the whole title Given two list of numbers create a new list and it should contain only odd numbers from the first list # and even numbers from the second list they still say it doesn't exist.
 
@PM2Ring yes good point, I just refactored it and figured the same thing
 
12:59 PM
@jigglypuff And actually, you can do tokens = line.strip().split() but it's just not useful here. And it makes the code harder to read. Generally, try to do one thing per line.
@AnnZen I'm still not understanding. Is there a newer question which you want to close as a duplicate of stackoverflow.com/q/62354860 ?
 
www.stackoverflow.com/questions/62359898/how-to-write-the-programme-below
 
@AnnZen Ok. But that question is closed now. And it's a slightly different question, since it has 1 input list & 2 output lists. The one you answered has 2 input lists & 1 output list.
 
Yes, I'm part of the closing votes. But I'm still confused, this is not the only time I tried to close a question a duplicate, but the message keeps telling me it doesn't exist.
 
Your answer is quite good, by the way. But the question is rather messy, and it could be confusing to use it as a duplucate target.
Your answer is quite good, by the way. But the question is rather messy, and it could be confusing to use it as a duplicate target.
@AnnZen That's weird. Maybe it's the # in the name, or something. To get the URL of a question, you should use the share "button" at the bottom of the question.
 
oh
 
1:15 PM
@PM2Ring ok thanks
 
The share buttons append your user ID number to the end of the URL. That way, the system can track when people on or off the site use links that you posted. And it will reward you with badges when lots of people click those links.
See Announcer, Booster, and Publicist at stackoverflow.com/help/badges
 
in the history of SO, have any user ever won all the badges?
 
Remember that Tabs vs Spaces question we deleted 3 weeks ago? I just noticed that it has 2 undelete votes.
@AnnZen I'm not sure. It's probably on meta, somewhere...
It's unlikely, because you'd have to be an expert in lots of languages to win all the tag badges.
 
1:41 PM
any trick to avoid new line at the end of the file bpa.st/TRNA
 
2:03 PM
I have a code that write something to a file, but it wont immediately detect the changes, not until i run the code again
how would it automatically or immediately detect the changes in the file without re-running the code or the program
 
@AnnZen Define 'all'? I doubt anyone has gold badges in every tag..
 
@aaa28 If you don't want a newline at the end of the file why are you writing a \n ?
 
What do you think about these type hints? Is it acceptable?

def calcSupport(data: {int: [str]}, itemset: [] or set ) -> int:


.
I want to denote that itemset is allowed to be either of type list or set.
It doesn't raise any error
In essence, what I am asking is whether the use of "or" in a type hint is considered okay?
 
Im sorry, I found the solution about the newline, I added the newline before the text instead, so it would not be added at the end
 
@SebastianNielsen I would have thought it would raise an error with [] instead of list, but I think itemset: Union[list, set] would be more conventional? I've never seen or used.
 
2:09 PM
Have you seen 'Union[list, set]' used often?
to denote a parameter should be either of the types.
Ahh, okay, it seems like it's convention: stackoverflow.com/a/33945518/7123519
 
Not specifically list and set, usually you might see Sequence(?) there I think. But yeah, Union is how you're supposed to denote a variety of acceptable types, as I understand it.
 
I think I prefer Union over Sequence. It's shorter to write and makes more logical sense to me.
 
@aaa28 I'm not sure what that code is supposed to do, but it looks a bit strange. What's kk? Why do you repeatedly call z = z.replace("0", "1") inside that for loop?
 
Well, at least my analysis of that code is backed-up by PM :) I think I translated it ok
Wait. I already gave you a new function@aaa28 here. Have you just ignored it, then?
 
actually I coded it base on my understanding, I just know what needs to be done, and using the tools that I know i.e the code snippets I scoured from the web, I put together to make it do what I want,
I dont bother to think about efficiency for now, or the pythonic way , I just wanted it to work, and maybe learn from it as I go along, so far its working as intended, except that, whenver the code write something to a file, it cannot read it back instantly, i just need to re-run the code, for it to detect the changes in the file,
 
2:23 PM
Except that it doesn't work (because you're asking here) and you've just posted the same broken code that I fixed.
 
well I am grateful for the code @roganjosh, the problem is I dont understand it, I wanted to solve my problems but I also wanted to learn, so I am putting it on hold for a while
 
@MisterMiyagi Yeah, I've just had to explain indentation to absolute beginners before and the Wikipedia page I linked has the best example I've found (it is frustrating that its not covered well in any of the official docs)
 
@aaa28 If you don't understand what I've done, that's fine, just ask me. It puts my back up a bit when you just ignore it and come back with an issue on the same code. I'm not saying that my alternative approach is the best, but you've gone back to the same code that confused me in the first place
 
well almost everything is working now, except for that part, the program, shows the user and options, base on the content of an external file, then the program gets an input from a user(the choice), match that input to the list, retrieved that item from the list, then modify it, and then put it back to the list, now the list being written back again to the file, then prints back to the user, the new content,the user will see the changes
dont worry I copied your code and saved in a text file, so I cant get back to it any time @roganjosh
the problem now with the code is as if the initial content was read, saved in the memory, then set aside, and only when the program, will it access the external file again
 
@aaa28 but you apparently don't understand it. I'm more than happy to explain what I changed, and I changed it for good reason. Don't be afraid to ask me to clarify something you don't understand. Fixing your entire problem will likely require more changes than the ones I made - are you just going to file those solutions away too?
 
2:39 PM
well when I think about it I can make it work before, I mean write the new content and read it instantly, the code of that is continuous, I mean it was not separated by functions, in my current code, every action is wrapped in functions
 
Which we discussed:
7 hours ago, by roganjosh
You don't need a function that just opens files. It's totally reasonable to assume that you'd also want to read the contents, so it seems like function 0 and function 1 can be consolidated into a single function
 
on the initial run of the program, there are action options, whether the user wants to read the file, or write it, or do something else, thats why I divided it in different functions
 
But, to move forwards, you will need to adopt the changes being suggested. Otherwise we're building on broken foundations
 
def function_0(a_file):
    with open(a_file, "r") as f:
        some_text = f.readlines()

    return some_text
 
... ok
 
2:46 PM
def main():
    a_file = 'location_of_file.txt'
    the_file = function_0(a_file)
    another_file = function_1(the_file)
 
@roganjosh I remember this person from the mysql tag - you will need garlic on all your food if you continue this conversation
 
@LinkBerest useful info. I'm not keen on garlic, thanks :)
 
oh, on a SQL note - I just saw someone (with 61 rep even) not only give an answer without injection but one that went on to fully explain why the OP's code was inject-able....was like finding a quintuple leaf clover :)
 
This doesn't happen. I'm now doubting your comment about garlic because you're making absurd claims :P
 
ugh..ran out of edit time and haven't had coffee yet (switch "why" for "that") but oh, it happened
 
2:54 PM
it must be hard to be so bright and shining, too bright its hot and burning, destroying everything it touches , everything on its path, too bad brightness also makes them blind.
 
I appreciate the concern, @roganjosh and got no beef with you, Its just I would just waste your time, cause Im not that bright, I just browse and browse and if a stuff is too dumb friendly then I grab it. at least I have the confidence, that I know in myself I know that stuff, and when I talked to others about it I know what I am talking about
 
3:09 PM
"cause Im not that bright" is something I really loathe. It doesn't waste my time if you ask me to clarify an approach to the solution I gave (it's not even a solution here for the bigger problem). Stop self-deprecating and follow-up on your questions. Whether that's a Google search or questions to me on what I proposed.
 
well its not a problem for me to ask you, cause you seem patient and hospitable, its just recently I feel like I need to have an SS Club membership to be welcomed
 
3:30 PM
@aaa28 Everyone is welcome at first. The less receptive of help someone is, or the more problematic someone gets, gradually the less welcome they will be.
 
3:46 PM
Are code only answers acceptable?
 
Im currently reading about rules, about the first item on the bulleted list,which is Be nice, about the Salad language and also about concerns of being excluded. I am the one asking question and asking help so I am not in the position to be choosy, but I wont just ask how high if someone told me to jump.
I grateful for every reply, cause it is very rare for someone to care, believe me Im gathering everything that being offered to me, I just need to process it and evaluate it, so that I can ask properly the appropriate follow up question and response.
I mean why would someone even bother, going here, if they are "less receptive, and problematic", maybe its not even about that, it's just frustrating, but I guess its true that everything has limitations, even kindness.
 
@AnnZen barely
You almost always should add explanation
There are exceptions, e.g. stackoverflow.com/a/33481152/5067311 and comments under it
 
@aaa28 Objective statements are not "un-nice". The reality for me, at least, was that I gave you a fix to an immediate problem and you just left it. That's not "nice" for me, considering it took me time to understand the issue and fire up my IDE, plus code things out, for no result.
 
@AndrasDeak This? stackoverflow.com/questions/50112359/… My flag was declined?
 
@aaa28 you'd be surprisee. And there's no rush to respond. You can "process it and evaluate it" in the speed it's convrnient. Respond when you're ready. Directed replies in chat make this easily possible to do.
 
3:54 PM
@roganjosh I am sorry if you feel that way, but I dont ignore your assistance, and I am very grateful for the effort, I have no problem with you, its the other guys,
 
@AnnZen the answer is clear considering the question.
 
@aaa28 But you did ignore my response
 
I did not, my question earlier the one you helped me with, is different from the concern I am having right now
 
There is no need to be sorry; I have thicker skin. But if you want to understand why people "have beef" with you, it's potentially because you're not moving forwards with their suggestions
@aaa28 eh, I'm done with this debate
 
00:00 - 16:0016:00 - 22:00

« first day (3528 days earlier)      last day (1405 days later) »