good point. I suppose I was just making an assumption based on your profile picture. If I have offended you based on my presupposed ideas based on how your profile picture looks, then I ask your forgiveness.
then again, I'm doing homework over christmas break on the other side of the world, in tropical India, in my parent's dining room, so I'm not really in a position to say
when comparing two strings in python, it works fine and when comparing a string object with a unicode object it fails as expected however when comparing a string object with a converted unicode (unicode --> str) object it fails
A Demo:
Works as expected:
>>> if 's' is 's': print "Hurrah!"
... ...
There's also something along the lines of 'ab'+'cd' is 'abcd' being False (I just checked and that specific example fails, but I have the right idea). I've read such a post on SO before. Anyone know which one I'm thinking of (link please?)
And really, that's not horrible. If it's not in a tight loop, you won't notice the performance difference. But, if it is in a tight loop ... You want to optimize it as best as you can. And you might as well get used to it at other times.
And, for what it's worth, after a while, I think that you get more used to reading it without that silly + to interrupt your flow of thought. the quotes are already bad enough.
Actually, I'm glad you brought that up, @mgilson. Is there a way to get the interpreter to implicitly understand that if I refer to a variable before it is assigned, I mean the str value of the varname?
I've used the ast module to parse python syntax and keep an index of all the names used -- And then compiled that tree. When you pass the compiled tree to exec, you can specify a locals dict which you could use to substitute in the names {'s': 's', ...}
Then have a dictionary returned from your functions.
But, this was all running on a web-server, and there seemed to be times when using non-string syntax for string literals would be good -- e.g. if there was a hole in the JSON returned from the API.
so, instead of getting {"foo": ..., "bar": ...}, I only got {"foo": ...}
Then instead of getting a NameError above on my webserver and having the user say "Why didn't my page load? what is happening?", they'd just have some random "bar"s in there...
then at least they have some sort of bug to report.
So we're not vulnerable to the typical __import__('os').remove('important_file') because of the globals I'm passing specifically set '__builtins__': None
But then, in the ast tree, I converted regular import statements to pass statements
I think it was Spolsky who said something like "don't make a feature before you need it, because you'll end up spending more time maintaining it, without even knowing if it will be needed".
But, the beautiful thing was that because of the ease of use of the AST module, the whole thing was about 150 lines of code. So, maintenance shouldn't be too bad.
I could be wrong. This was for a program that I was using to prove my master's thesis and I was in zombie mode while coding this. So I can't entirely trust my memory
(will check back on the code and see if I can find the spot)
Does windows have a terminal emulator installed by default? I'm writing a short manual for a program and I need to know if I need to tell the user to download one, or if there is one already installed
@GamesBrainiac that's not entirely true. I could write code that would effectively be a regex, and that would be less suboptimal, given that I'd have complete control over the code
@inspectorG4dget Well, not entirely, sure there are certain cases where a composite regex might be faster, but most of the time there's already an inbuilt alternatives.
File extensions? You have the os module.
Basic string finding and manipulation? You have the string module.
Consider this, @thefourtheye: suppose I gave you a list of words and asked which of them matched a certain template. I could easily write a loop to check each word; and checking each word would require a loop on the word and a parallel loop on the template. This would effectively be a regex. However, there being an existing implementation (import re) for this exact problem already, you may as well just use it
@thefourtheye no I just didn't update the manual yet. the f command with the -q flag (f -q) factors a quadratic formula and the csq command completes the square of a quadratic