« first day (4038 days earlier)      last day (1133 days later) » 
05:00 - 19:0019:00 - 00:00

05:54
I think Raymond Hettinger just revenge-downvoted me for criticizing his latest answer.
Frustrating to have a core dev do that.
07:01
Yikes
yeah.
can anyone explain "fails on inputs like list, which is hashable even though"? hash([1]) fails right?
where is that from?
ohh my bad
I think this is the question they are talking about
oh -_-
first off, it's such a baseless acquisition i dont even wish to entertain it further
    stringURL = f'https://api.coingecko.com/api/v3/coins/{self.pair}/market_chart/range?vs_currency=usd&from={self.fromm}&to={self.to}'
    print(stringURL)
    respdf = pandas.read_json(stringURL)
07:12
I dont mean to question that, I just genuinely want to know why or how, maybe I am missing something
second, lists are unhashable
prints fine, but throws error when read_json() called
shouldn't you call the api?
huh, you can pass in a string and pandas would call it apparently
apparently its not working, error
what error
07:16
urllib.error.HTTPError: HTTP Error 404: Not Found
well. that answers* it. no?
but i need to make the string first from the instance variables and then the stringURL should be called by pandas, any url is called fine by pandas and then i got this error
do you understand what the error is saying?
i'd start there. can you google "what is HTTP Error 404: Not Found" and see what it says?
error messages contain useful information, try picking up the habit of reading them so you know what the issue is. if you dont know what an error message is saying, start searching for it online
07:21
respdf = pandas.read_json('https://api.coingecko.com/api/v3/coins/zilliqa/market_chart/range?vs_currency=usd&from=1633975200&to=1635271200')
this works
net suggests import requests
doesnt work either
so what meaning did you find for the error message when you searched for it? what does "HTTP Error 404: Not Found" mean?
it means http link not exist
so u think the link got messed up somewhere?
good.
exactly, now that you understand the error message, you immediately can look at where the issue actually is. check the url that's actually being made
changing libraries wont change the error if the url itself is wrong.
hmm solved it already
well done
07:30
@ParitoshSingh u r like a teacher
@python_user @user2357112supportsMonica can surely explain, he's right there. But look carefully: list is hashable. The type itself!
ahh ok, hash(list), that makes sense
07:45
Hello people! (first time here on chat) I was wondering if the "if __name__ != '__main__':" statement is considered ok to be used in the development of libraries (because i've only seen it being used in non lib files)
!=.. i havent really seen them in the wild anywhere. so i imagine generally it would be considered a potential code smell. but it depends on what exactly you need to do
unless you meant to ask about if __name__ == '__main__': which is a lot more common
no you are correct, i meant !=
I have never seen that
Hi, I have a little problem with frappeframework.
Basically, I need to attach QR code generated dynamically to a doctype and then print it.
Currently, from server side (python), I am getting an encoded string (I can also get a pixel 2d array if that helps). On client side (js) I have an HTML field (a frappe framework field), and I am using a js library 'QRious' to render QR code from the encoded string and set the value on HTML field. This is working fine and the QR code image is displayed but HTML field values are not saved so I am in a bit of a pickle.
then my initial hunch would be to double check if there's a better way to do whatever i just did. for example, say wrap logic in functions or classes, so that actual code execution doesnt happen when you import a module
i imagine having to use != is an indirect sign that you've got some weird state issues with logic floating around in the global scope
first i want to prevent the user from executing the file as main. Second to use it as a debug or print-info mechanism too
07:51
@GiorgosXou why prevent users explicitly. you could always just rely on convention for it with an underscore prefix
for debugging, use a proper debugging library with the correct levels set for development or debug
@ParitoshSingh oh i see. thanks (:
i stink a lot when im coding, is it normal?
hahaha
@ParitoshSingh if __name__ != '__main__': implies that the guarded code will be executed only when the module is imported. I can't imagine that will be helpful: it's a "code smell," which may reveal a structuring issue.
@holdenweb why so?
anyways it's not that it is anything that "import ant" xD
08:04
Because there's no reason to execute code only when you're being imported. If you don't want people to execute you as __main__, just add a if __name__ == '__main__': raise NoDontDoThatException
@Aran-Fey ok i agree..
can u explain with open?? open is a method, if i understand correctly, but what is with keyword? what else does it do?
08:23
@Aran-Fey but wouldn't be great if the main part of the lib that gets first executed (that in my case [it has no class and] is just a few lines and it's purpose is only to do an if statement and load the appropriate lib for each OS), would have been under a function instead of just in the global scope? and if yes then if i had to use alot of the global variables in this specific part of code, wouldn't it be better if that code was under a structure like "if __name__ != '__main__':" ?
.
let me guess, NO xD
I don't quite understand the situation you're trying to describe, or how a if __name__ != '__main__': helps there, sorry
@Aran-Fey it's ok anyways, it was more of a thought rather than anything else
@GiorgosXou all other things aside, the proper pattern is so fundamental that nobody would notice the != where an == should be. Don't write code like that.
But now I understand the upside-down avatar :P
08:40
Hey guys Quick one very opinionated question... I am looking to learn a low level language in my free time for fun, coming from Python| JavaScript and PHP so far what would be better C | C++ also thinking what would be better careerwise?
@holdenweb I'm not sure what your last ping was refering to. I guess about the enum and reference table discussion?
@AndrasDeak wow I read the thing and alread read ==. Yeah don't do != This part is so idiomatic it will throw everybody off. Human autocorrect is strong
@AndrasDeak Good read that so guess not low-level then xD still probably a good idea for me to learn one of those before going to much further down so I can learn the things python does for us pointers and memory management, correct?
09:02
if you want pointers go C
@AndrasDeak Very interesting read
Do you know if rust has the same problems? I heard good things about it
I know exactly two things about rust: 1. it's supposed to be "C done right", and 2. you have to think hard about lifetimes and stuff even for the simplest of programs.
my understanding is that 2. is the price of 1.
Eternal fight with the compiler instead of a sea of undefined behaviour that "works on my machine on every second Tuesday".
But, again, that's a completely uneducated impression.
@AndrasDeak xD
09:47
My feeling of using the Rust compiler is less fighting and more benevolent-head-shaking-at-what-the-toddler-did-this-time.
 
2 hours later…
11:30
cbg
Is that common practice in open source, for a repo owner to take a contributor's PR, force push it to one of the owner's branch, recommit it, and then merge it with the comment `authored by contributor, committed by repo owner`?
It rubs me a bit the wrong way as I am more used to having proposed PRs merged, but I want to make sure I am not missing something.
Seems unnecessary, yes. Check if there's some contributor's guide that explains it.
Thanks @AndrasDeak - no, there is no contributor's guide.
That process seems weird to me. Usually the maintainer just merges the PR and that's it.
yes, that's my experience too. What could be the reasons for this process?
Are they doing this as a manual process? Squash-merging a PR would look somewhat similar to what you describe; the system creates a new commit of all changes and attributes it to the author (who made the initial commits) and maintainer (who "owns" the squash commit).
11:40
There could be CI tooling around branches, but I've seen that work just fine with contributor branches with the appropriate name.
I guess you'll have to ask the maintainer what's going on
If it's a small enough repo there's also the possibility that the maintainer doesn't know what they are doing
I assume this is github or gitlab which both have tooling around PRs
It is a small repo, but the maintainer knows precisely what he is doing... There is more automation code for the docs and CI than code in the repo! :D
I asked, the CI track is probably the reason. We'll see.
It is hard to say @MisterMiyagi, IDK
perhaps they only want signed commits, but squash-merge would do that anyway I think
There has to be a reason, but it would be nicer if it was explained upfront - I'll suggest a contributor's guide.
It's not clear to me that there's actually a new branch involved. Seems more like your commit being replaced with a joint signed commit (on the same branch, hence the need for force pushing)
and there's always only one commit per PR, so squash-merge it must be anyway
it is on a new branch on the upstream, not on my branch.
11:48
OK, that's not clear from the UI
I didn't even know you could replace branches under PRs
neither did I!
you can't
at least that's not what happened here
Look at the branches on the repo. There's only 2: master and one from dependabot.
If there were a branch on the repo itself you'd see that there
It was merged; the changes from my PR are on the upstream master SCRATCH THAT, it was not merged, and the changes are not visible
All right, I am confused; I don't understand why , but I asked and I will find out; there has to be a reasonable explanation.
Thanks for looking into it and sharing your experience.
12:14
morning cabbages, folks
13:02
Somebody got experience with any of these suggested solutions? stackoverflow.com/questions/2352181/… The comments to each answer make me vary that here lie dragons, but still this seems like a straightforward feature, kinda
13:54
hi, how to filter dataframe with such behavoir:
filter by rows, than any column can contains string 'high'
rules_min = rules_min.loc[rules_min['antecedents'].str.contains('high')] I wish I could do that, but it only check 1 column 'antecedents'
take a look at what happens when you run .str.contains directly on the dataframe, instead of choosing one col
you may need to collapse the result along a specific axis
(turns out it raises an error. good to know...)
if you need to check just whether the value is equal to 'high' you could just use == instead. do you?
14:21
Hi! is there any way to run C using python. If it's possible, what would be the easiest way to do it. Thank you for any help in advance. :)
definitely possible. i've never done it myself though
IIRC ctypes is good for that
Consider also Cython, which "calls back and forth from and to C or C++ code natively at any point."
14:39
hey guys, back again, does adding more tag means more views? my new question seems to get like 1 view a minute
hello al, is there a way to write if statements in multiple line, if the condition you are checking is too long
?
@ozil Yeah. The easiest way is to put the condition inside a pair of parentheses. Then Python will know that it should check the next line if the expression isn't complete yet
@Jake tagging it "python" will definitely get you more views. And any third party libraries that you're using. Adding stuff like "for loop" tends not to have much effect, though.
thanks @kevin
same as what he said :D
could you send me an example, if possible. indentation is confusing me
14:44
thanks :p
@Jake In theory It should. Adding more tags should increase the audience your question is seen to. But just like @Kevin said adding very specific tags would be meaningless.
>>> if (1 +
...     2 > 3 -
...     0.1 or
...     "dog" == "cat"):
...     print("cabbage")
...
cabbage
@Kevin - awesome thanks
IIRC the indentation of lines 2 3 and 4 don't actually matter, just the indentation of the if and the code block after the colon
wow, that actually works?
14:46
>>> if (1 and
...                                                     2):
...     print("cabbage")
...
cabbage
If you don't like parens, you can also use line continuations to tell Python that the upcoming newline isn't the end of the statement.
>>> if 1 and \
...                             2:
...     print("cabbage")
...
cabbage
cool. thaks
thanks
I don't care much for it myself, but YMMV
@Kevin Thanks for the parens tip. It would really help me clean up my code.
I did not know this too, thank you
python.org/dev/peps/pep-0008/#multiline-if-statements discusses style considerations involving multiline if
14:54
black has an opinion on this
if (
    long_condition_with_a_very_long_example == 1
    or long_condition_with_a_very_long_example == 2
    and long_condition_with_a_very_long_example != 3
):
    print("hi")
this is the kind of stuff they suggest.
Sensible
I'm not too consistent with my placement of ): much to my shame
such is the life of the sad face.
Living in the shadow of his more popular brother ":(", no less
it took me a while to understand this, lol
@holdenweb Essentially I have a site with a node.js frontend and django backend. I am using an Apache HTTP Server on CentOS7.
@holdenweb I setup the dev server where the frontend is being served to myIP:3000 and the backend is on myIP:8000. I am trying to move a build to prod. So, I ran my npm run build and pointed the DocumentRoot of my httpd.conf file to the i.e. /var/www/myproject/frontend/build.
@holdenweb This serves up my homepage just fine when I just visit myIP. But the links are generating 404s which leads me to believe that I need to adjust some sort of additional configuration in either the django.conf file or the httpd.conf file.
15:03
For future reference, try not to ping people multiple times in consecutive messages. It will save the recipient a couple beeps and/or inbox notifications
Thanks, Kevin
If the homepage loads but not any child pages, it might be a problem with routing... I will peruse the documentation
My current advice is "add lots of logging, and read the logs"
15:24
Hi, can anyone assist with a pandas question please?

https://stackoverflow.com/questions/69853495/df-groupby-sum-isnt-returning-the-expected-output
I agree with divingTobi and furas on this one. Please provide code that creates the df object and populates it with sample data.
You might be thinking "but I already typed up the data under the section starting with 'Here's an example of the data I'd use'. Can't the readers of my question convert that to a dataframe themselves?". Not necessarily. I myself am quite bad at getting pandas to parse plaintext data. If I have to do it myself, then I've spent half my energy before I've even had a chance to experiment with the problem
@Kevin Hi, thanks for answering. Sorry, I'm new to Stackoverflow and using Panads. I'm not really sure what you mean when you say create the df object and populate it with the sample data. Is there another post or article that can explain what it is you guys want me to do to make it easier for people to answer the question? :) Thanks in advance.
for item in a list:
if (somevalue ==true):
if (someother value == true):
break
sorry the for the indentation . if i have a if statement within another if statement the is inside a for loop. if i break from inner if statment , will it break out of the for loop?
for item in a list:
@cchev stackoverflow.com/help/minimal-reproducible-example gives good general advice on that. I can go into more detail about pandas-specific advice in a minute
@ozil Yeah. The break should break out of the for regardless of how many if blocks you're inside.
15:39
@Kevin - thanks
Consult tinyurl.com/urnzp7k for advice on indenting in chat
@Kevin When you say provide the code that populates it with the sample data, isn't that the full code I've provided in the question?

At the top where I've put 'heres an example of my data', that's all the data I'm working with on an excel sheet. I'm not really sure how else I can format the question or give more detail :/
Readers usually only consider code to be "full code" if they can copy-paste the entire block into notepad, save it as myprogram.py, and run it
If I do that with your code, I get NameError: name 'df' is not defined on the third line.
Oh I see what you mean. How do I fix that though? df is the location of the excel file
apologize for the random questions here. i have one more , if i have a list in python , say, items= [] . what is the best way to see , if it is empty or not?
15:48
Mm hmm, this is a common problem in Pandas questions. In the asker's real code, they're creating df by reading data from an excel file or database etc. The readers don't have access to that file, so that code wouldn't work for them even if you included it in the question.
@ozil if my_list:
@roganjosh - thanks
The most straightforward approach is to create the DataFrame inline: df = DataFrame({"foobar": [1,2,3], "baz": [4,5,6], "cabbage": [7,8,9]})
Empty lists are falsey
... To give one example. I'm pretty sure there are other ways to make a dataframe without any external files, but this is the first one I tried that worked
15:50
That makes sense. Thank you for clarifying the issue, I didn't quite understand how it was an issue in the question but now I see!

I'll look into it and try and reformat the question. Thanks @Kevin
Ok :-) I'll be happy to take a look at the actual problem too, once I can play with the data
@Kevin the go-to to prove this is tensorflow
Or at least it is for me, anyway
shudder...some things should be left unproven.
FWIW I find it illegible in many cases. But it proves the concept that 4 spaces is only a guideline
Overall I think it's a good thing to allow weird indentation for multiline expressions. Of course, the programmer should be mindful of how much weirdness they and their readers can tolerate
15:59
Sorry, I take my comments back. I think I misinterpreted the statement. Not sure I have anything to add to the actual issue
We can switch topics to whatever you thought the issue was :-) I'm not picky
For a few months, I've adopted the practice of using 2 spaces of indentation for multiline expressions.
Quite regularly, I ignore that asker's actual problem and instead pontificate on solutions to what I wish the problem was
It makes it more obvious that it's not a real indented block. And it's more convenient when coding on my phone, where long lines are painful. ;)
Concept: a mobile IDE that renders four spaces as two spaces
If you're willing to make all spaces skinny, perhaps you could do something clever with a custom font
Edit Courier New so its space is 2px wide, and leave everything else the same
16:05
@Kevin That's tempting. I actually used 2 space indents for a while when I first started with Python. But when I look at that code these days it looks very cramped.
I use two space indent for javascript code, and it takes a couple minutes to shake off my Python instincts
"The tab button only moved my cursor half as far as usual... Is it out of fuel???"
I don't like the idea of reducing the space char width, though. Code should be in a monospace font. It drives me crazy when I see code in a proportional font.
All right, you've convinced me. We'll make every character 2px wide.
I wrote an awk script that can re-indent code. It's fast but not very smart, so if the existing indentation is stupid, Bad Things can happen.
I have a small collection of minimum size bitmap fonts, which I collected for my "home-made" e-book reader. Things tend to get illegible when the char width is under 5 pixels. :)
You could probably write something fairly robust using the tokenize module, although it would probably fail on some kinds of syntactically invalid inputs
An "unexpected EOF" program, like def f(): print("Hello", it could probably handle gracefully. More flagrantly wrong syntax is a gamble
16:16
I got a cheap mini digital photo frame. It can store 120 BMPs. That's not much, but it's enough for a couple of hours reading. And the photo-frame is quite small, about 1/3 the size of my phone. I assume it still works, I haven't used it for over 5 years.
@Kevin I wanted my indent script to work for a bunch of languages, so it's oblivious to syntax.
A sensible requirement.
I read a lot of short scifi stories off Project Gutenberg on that photo-frame. And most of Harry Potter & The Methods of Rationality.
Why are you coding on your phone, PM?
Ah, Project Gutenberg. I admire their mission but I have trouble searching through it for diamonds in the rough. If you happen to remember some titles you liked, I'd be keen to hear about them.
I can understand for things like SO but it seems like you're made an active choice when you mention it several times
16:24
I've mentioned that photoframe thing here a few years ago. Eg
Apr 8 '16 at 11:32, by PM 2Ring
user image
PM's best code only arises when he treks into the unmapped wilderness. You can't bring a laptop with you, since that makes the area's wildness rating drop
@roganjosh Because I can. :) I've only rarely turned my computer on in the last year or so. It's kind of more comfortable working on my phone. Maybe I need to get a better desk chair, or something...
I think I'd just end up launching my phone at a wall :P
Repurposing a picture frame as an e-reader is good hacker ethos. Fight the Establishment's insistence on selling you gadgets that can only be used for exactly their advertised purpose
@Kevin I'll retrieve some titles for you next time I turn my computer on...
16:34
Thanks :-)
No hurry if it takes you a year or so. Likely I'll still be in the market for good stories
One classic series from Gutenberg that I can recommend is Campbell's Arcot, Morey and Wade series, see en.wikipedia.org/wiki/The_Black_Star_Passes
I love a good retrofuturistic book cover
The series is certainly dated, but it's a fun read, if you approach it as a piece of influential scifi history.
I wonder if any particular pioneering work popularized the idea of fishbowl helmets that are transparent all the way around. It's not particularly practical to have glass where your eyeballs can't point.
Campbell had a huge influence during the scifi Golden Age as an editor, and helped shape a lot of the early Asimov stories. But he was a pretty good writer, too. If you like E. E. "Doc" Smith, you'll probably enjoy Campbell. They're a similar vintage.
16:41
I guess if you account for a bit of neck mobility, you could round up a human's potential FOV at 270ish degrees. Maybe scifi cover artists tried drawing helmets with an opaque mohawk stripe, and they were like "yeah this is just as silly as a fishbowl"
@Kevin Good question! And maybe worth asking on the SF&F stack.
Hmm, I'm tempted.
The fishbowl shape is strong, which is a desirable property when you're dealing with a bunch of glass surrounding your head.
My guess is it was devised by an artist, rather than a writer. You want to be able to see the hero's face.
Perhaps there was a runaway survival of the fittest, akin to peacock plumage. Suppose the first fictional spacesuit was identical to contemporary diving suits, complete with a dinky little 4 inch viewport. An aspiring writer would think "maybe materials science is better in the future, so they can manufacture a wider viewport without compromising structural integrity", and put 6 inch viewports on the helmets in their story.
If the audience responds positively to this, and the talents of the industry discover the "wider viewport -> more futurey" relation, then it's only a matter of time until the viewports take up the entire perimeter of the helmet.
Sounds plausible.
17:03
cbg
cbg, Code-Apprentice
how is the python world?
Project Gutenberg also have a lot of H Beam Piper's work. en.wikipedia.org/wiki/H._Beam_Piper
Python's slithering along as usual.
Jul 22 at 13:13, by PM 2Ring
@AlexandreMarcq Some recent additions to Python are directionally ambiguous. Some people think they're advanced, other people think they're retarded. ;)
Hi, I have a problem of finding multiple bounding boxes in a 2D-space from a set of point. I know how a global bb can be found, but how would I calculate bounding boxes of clustered points in the same list? Is there any research on this problem? I think a sweepcast of a constant distance for every point and defining those as neighbors and afterwards look up which points make up a cluster will work, but this is sort of brute-force method
What is the context?
17:18
i have a empty list , itemlist = [] and i append to this list if item search is found . if not , i return a 'not found' message. my return statement is , return itemlist if itemlist else itemlist.append({'msg': 'not found'}). this should return
If the problem is just "find the clusters in this list, then find their bounding boxes", I imagine you could apply typical cluster analysis methods to the first part.
so this should return , item with this item -> { 'msg': not found }, if itemlist is empty at the end of the function right?
@McMidas Depending on the context, this may be helpful: en.wikipedia.org/wiki/K-means_clustering
@ozil itemlist.append returns None, so I'd expect your function to return None some of the time.
@Kevin - oh ok thanks
@Kevin - is there a way to return itemlist with {msg:'not found'}
in a ternary statment like that
?
17:21
@roganjosh for recognizing textregions, i have the coords of the words already, but want to crop those as individual images for further processing
Yes, although I don't consider it good style
@PM2Ring interesting, just as the k-nearest-neighbor classifier approach
I would much prefer to simply separate the return statement from the append statement: if not itemlist: itemlist.append({'msg': 'not found'}) followed by return itemlist on the next line
@Kevin - thanks
@McMidas sorry, then this is way out of my field
17:24
Or, now that I read the problem again, I would just not bother to append to itemlist at all, and construct a brand new list literal around the dict literal. return itemlist if itemlist else [{'msg': 'not found'}]
return itemlist or [{'msg': 'not found'}] is also a possibility but that style of short-circuiting is more at home in Perl than in Python
This doesn't make sense to me
It returns a list and it's either empty or not?
Why should it contain the message itself? Wrap in a try/except and handle it from there. Making a ternary is confusing to me
a simple solution can be to perform morphological operations such as dilatation so that the textlines merge together and then i would do cv2.findContours() to retrieve those, but my image does not only contain text, so it will fail here
I'm somewhat on roganjosh's side -- I also raised an eyebrow at the structure of the object being returned here. Returning a list of dicts of error messages is fairly unconventional.
But I myself have returned a list of errors from a function before, so I'm open to the possibility that there's a sensible justification.
@Kevin, @roganjosh - thanks for your insights. I will revise this
17:41
@Kevin I believe it's formatted in a way for people to answer it easier now. I hope so anyway :D

Please could you review the question and let me know what you think?
https://stackoverflow.com/questions/69853495/df-groupby-sum-isnt-returning-the-expected-output
Hello!
Trying to get all python files within some folders :
X = []
for dataset_path in directories:
    print(dataset_path)
    samples = [f for f in listdir(dataset_path)]
    for file in samples:
        file_path = dataset_path + "/" + file
        print(file_path)
        X.append(glob.glob(file_path+"*.py"))
I tried this, it does not work :/
listdir will get all folders within a directory, then we build for each foldera file_path, then we use glob.glob to get all .py files within that folder.
This is my approach.
@cchev Sure, I'll take a look
@Avra Hi. Is that listdir function from here: docs.python.org/3/library/os.html#os.listdir ? It lists files & directories. Make sure samples contains what you think it does.
It's a little odd to use listdir and glob at the same time. If you're using glob, it can usually do everything you need on its own.
Thanks @Kevin. I appreciate your help so far :D

I'm not sure what a glob is
17:56
It's a module that can be used to search for files. I was talking about Avra's problem, so you don't need to worry about it :-)
Oh good good
I have 100 folders within each other
One folder might have 20 folders before I can reach the file while another can have only files
So I am trying to loop over all 100 nested folders and get files that might appear at any level
@avra I agree with Kevin. :) Also, a more modern option for handling file paths is pathlib docs.python.org/3/library/pathlib.html
glob can look through multiple levels, IIRC
I will check it, but I have multiple levels though
One folder has 20 nested folders before I can get "*.py" files
so you recommend to use glob not pathlib?
18:01
Yes, glob can do recursive searches docs.python.org/3/library/glob.html
The pathlib module also has globbing ability.
@PM2Ring. Thank you. I will check glob
@PM2Ring. WOW!
It's probably easiest to use the glob module. But it's worthwhile to eventually learn pathlib. It's good for traversing existing directory trees, and also good when you need to create new directory trees.
It's very fast! OMG
directory = "..//data"
pathname = directory + "/**/*.py"
files = glob.glob(pathname, recursive=True)
len(files)
I got all 140312 files in 5 seconds
Does glob use binary search tree with log(N) time!
@Avra Glob does most of its work at C speed.
OMG!!
Never saw something fast like this
Python + C is ultimate power
Even Java does not do this
18:09
Here's an old demo of mine that shows how to use listdir recursively. stackoverflow.com/a/33914896/4014959 It's slower than glob, but it lets you do stuff as you're traversing the directory structure, which can be useful in some situations.
@PM2Ring. I see with log(140312) we need 5 seconds!
Binary search seems unlikely here since it would only be possible if the file system already had a list of files, sorted by extension name. I don't think file systems usually know what an extension is, to begin with
How it does this so fast then?
C is just like that :-)
:(
I think I will learn C
I know C++
basics at least
Did it 10 years ago :/
18:12
I think everyone should learn a variety of languages. It's good experience.
Java is very slow, what do you think!
Java runs slower than that
My Java projects are rarely fast, but they're usually fast enough.
Great
@PM2Ring. @Kevin. What are your top 3 prog languages?
Probably Python, JavaScript, C#
@Avra Kevin has created his own language, KevinScript.
18:17
I love your choice :)
but not fan of C#
I will do same but Python, JS, C
KevinScript is implicitly at spot #0 of all my top ten lists :-p
hahah
How much time do you think one needs on average to master Python and C?
I mostly write in Python these days, and occasionally JavaScript. But I've learned a lot of languages over the years. I've been coding since the early 1970s. I wrote a lot of C for a few decades, but I've hardly used it at all since I learned Python.
@Avra 3
3 years?
18:20
Just 3.
haha
what is 3?
I'm trying to illustrate that the question is unanswerable
I think this must be a zen riddle. It's the same amount of time as a finger pointing at the moon, or the taste of a berry growing on an unclimbable cliff
you are right depends on person
Hofstadter's Law: "It always takes longer than you think, even when you take Hofstadter's Law into account".
18:22
Yesss
It also depends on what you think "master" is. We've had core developers ask questions here
A really important part of writing good code that's easy to understand is coming up with good names. It didn't take me long to get ok at the logic of programming, but it took at least 20 years before I got ok at naming things.
Aug 15 '15 at 14:14, by PM 2Ring
"There are only two hard things in Computer Science: cache invalidation, naming things, and off-by-one errors." – Phil Karlton & Leon Bambrick
@PM2Ring. I got an issue as some folders paths had "\\" instead of "//" with glob
I had to store all file paths in a list and loop through them again to replace "\\" with "//" as follows:
for x in files:
  list_files.append(x.replace('\\', '//'))
I don't know why glob did that though!
@Avra Are you using Windows?
Be careful, "\\" is a single backslash char.
Oh!
I got that error while trying to copy files I stored in a list to another folder using shuttil lib
shuttil.copy give permession error due to "\\"
22
Q: using shutil.copyfile I get a Python IOError: [Errno 13] Permission denied:

DrDarkI have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy' des='C:\Documents and Settings\user\Desktop\\tryPy\Output' x=os.listdir(src) a=os.path.join(src,x[1]) shutil.copyfile(a,des) print a It gives me an error: IOError: [E...

I found this solution
18:36
@Avra We don't usually post "one-box" links like that in this room, unless they're very important.
That question doesn't seem to have anything to do with backslashes vs forward slashes
@PM2Ring. Sorry. I will avoid that in future
Thanks. You just need to include some other text with the link to stop it one-boxing.
I am using windows 10 yes, I got [Errno 13] Permission denied: as I stored all file paths in a list, then I tried to copy them to a a folder that has all .py files, but I got permession denied both using shutil.copy and shutil.copyfile
FWIW, shutil.copyfile works perfectly with "\\" on my machine. No permission error.
C:\Users\Kevin\Desktop\deleteme>mkdir foobar

C:\Users\Kevin\Desktop\deleteme>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.copyfile(".\\test.py", ".\\foobar\\test.py")
'.\\foobar\\test.py'
I'm on Windows 10 as well.
18:40
@Kevin IIRC, Windows ignores any extra backslashes (or extra slashes). Is that correct?
Note that when I used copyfile, I specified the name of the file for both arguments. You can't copy test.py to foobar just by writing shutil.copyfile(".\\test.py", ".\\foobar")
Oh!
@PM2Ring Let's see. I ran shutil.copyfile(".\\test.py", ".\\\\\\\\\\\\\\\\\\\\foobar\\cabbage.py") and it put cabbage.py in the foobar directory.
So in my case I have to use copyfile for thousands of files
copy worked fine, but I got permession denied at file 35120 for having "\\", so I repalced all file paths that have "\\" with "//", but still have same issue
Right, I just proved that "\\" works fine and you never need to replace it
18:44
Yes you are right because even after replacing it same error!
@Avra Are you telling it to copy a file to a directory that doesn't exist?
No. I already created a folder named python that will have all python files that I stored their paths before in a list using glob
This happened with me before. I think permession error is cause these files most likely written in UNIX system
I have a couple of theories that could explain this problem, but it would take a long time to describe each of them and have you check. Instead, I'd like you to provide an MCVE, so I can quickly check on my own.
So you're copying thousands of files into a single folder? There are no other folders in that folder?
Nope just ONE folder named Python
18:48
Unix does allow some filenames that are illegal on Windows.
UAC is where my money is at
all files already had their file paths stored in a list
Disable User Account Controls and try again
disable it on the location where I want to copy files to not the source?
It has to be disabled globally. Maybe Kevin has a cleaner idea, but that will get in the way (IMO)
The first thing I do with a Windows system is disable UAC. For better or for worse, but I take the risk
18:52
Oh!
I set it to never notify me
My ideas are clean and beautiful like a polished pearl, but the clam will only open in the presence of an mcve
@roganjosh. Same issue [Errno 13] Permission denied:
05:00 - 19:0019:00 - 00:00

« first day (4038 days earlier)      last day (1133 days later) »