Re: How ahead are you guys in the (Python) real world?
Ray wrote: > Since I haven't used Python at work, I am using Python 2.5 right now. > However I wonder, how fast are you guys moving from version to version > at work? As an illustration my ex-company just moved to Java 5, which > was released around... what, 2-3 years ago? (While I am running Java 6 > at home) > > Is it the same in the Python world? What version of Python is used in, > say, Google? Is it even 2.4 yet? Heya, here at my job 2.3 is a must , but the code *should* be as compatible as possible with 2.2 too. -- http://mail.python.org/mailman/listinfo/python-list
Re: python loops
`range' is especially useful for iterating over long sequences ;-) for i in range(0,100) : OverflowError: range() result has too many items Sybren Stuvel wrote: > [EMAIL PROTECTED] enlightened us with: > > I thought the xrange was preferred? for x in xrange(length): > > True. It doesn't create the entire list, like range does. range(1000) > creates a 1000-element list. xrange(1000) just iterates through the > appropirate values. > > > The information contained in this message and any attachment may be > > proprietary, confidential, and privileged or subject to the work > > product doctrine and thus protected from disclosure. If the reader > > of this message is not the intended recipient, or an employee or > > agent responsible for delivering this message to the intended > > recipient, you are hereby notified that any dissemination, > > distribution or copying of this communication is strictly > > prohibited. If you have received this communication in error, > > please notify me immediately by replying to this message and > > deleting it and all copies and backups thereof. Thank you. > > And how are we supposed to interpret this? Copying this communication > may be prohibited, but both email and usenet messages are copied all > the time. Without that, both systems fail miserably. > > Sybren > -- > The problem with the world is stupidity. Not saying there should be a > capital punishment for stupidity, but why don't we just take the > safety labels off of everything and let the problem solve itself? > Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Spliting a string on non alpha characters
Hello! I'm relatively new to python but I already noticed that many lines of python code can be simplified to a oneliner by some clever coder. As the topics says, I'm trying to split lines like this : 'foo bar- blah/hm.lala' -> [foo, bar, blah, hm, lala] 'foobbbar.. xyz' -> [foo, bbbar, xyz] obviously a for loop catching just chars could do the trick, but I'm looking for a more elegant way. Anyone can help? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
Usually, when I make some coding mistake (index out of range - in this case) I just care to fix the mistake and I usually don't mind to inspect by how much the index was overflowed. It really seems like a feature that should be embedded in some Python debugger than a feature in the interpreter itself. -- http://mail.python.org/mailman/listinfo/python-list
Re: skip last line in loops
lines = open('blah').readlines()
for i in range(0, len(lines)-1) :
print lines[i]
[EMAIL PROTECTED] wrote:
> hi,
> how can i skip printing the last line using loops (for /while)
>
> eg
>
> for line in open("file):
> print line.
>
> I want to skip printing last line of the file.thanks
--
http://mail.python.org/mailman/listinfo/python-list
Re: One module per class, bad idea?
Matias Jansson wrote: > I come from a background of Java and C# where it is common practise to have > one class per file in the file/project structure. As I have understood it, > it is more common practice to have many classes in a Python module/file. > What is the motivation behind it, would it be a bad idea to have a guideline > in your project that promotes a one class per file structure (assuming most > of the programmers a background similar to mine)? IMO, even the Java practice is weird. I think classes should be split into different files/modules due to their context and not their number... -- http://mail.python.org/mailman/listinfo/python-list
Nice "bug" to loose a contest
Hello,
Yesterday, I was at a programming competition. We programmed on Linux
liveCD's and Python was one of the allowed languages (among C and
Java). I cared just about the algorithmic approach so I used Python.
One of the main rules is, that the code reads its standard input and
dumps the result on the standard output. Here happened my bigger
programming mistake ever - I used the following approach :
import sys
print sys.stdout.readlines() # TYPO ! stdin != stdout
So the WEIRD issue is, that it worked and, executing the following
code I get :
[EMAIL PROTECTED] ~ $ python la.py
test
test #2
['test \n', 'test #2\n']
[EMAIL PROTECTED] ~ $
Ok, as the algorithm worked perfectly, and all the test cases we were
given were positive, I've continued with the next problem, copy/
pasting the above idiom... When they tested the code, they used file
redirection like :
==
python la.py < /somefile
==
And, my code resulted in no output/input (=> 0 points), which can be
proved here too :
[EMAIL PROTECTED] ~ $ python la.py < /etc/passwd
===
Some friend of mine told me that's the Unix way, (stdout can act like
stdin) so I tried some C code :
===
1 #include
2
3 int main() {
4 char buf[120];
5 while (fgets(buf, sizeof(buf), stdout) != NULL) {
6 puts(buf);
7 }
8return 0;
9}
===
The code returns with no delay, so I'm really wondering where is that
nice sys.{stdin,stdout} feature inplemented as pydoc doesn't mention
anything. I'd spot the mistake before submitting the problem solutions
if it was written in C :)
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Program inefficiency?
On Sep 29, 6:07 pm, [EMAIL PROTECTED] wrote: > You did not mention the OS, but because you are using > "pathname\editfile.txt", it sounds like you are using an MS OS. From > past experience with various MS OSes, I found that as the number of > files in a directory increases the slower your process runs for each > file. how so? -- http://mail.python.org/mailman/listinfo/python-list
why I don't like range/xrange
Hello! Many times I was suggested to use xrange and range instead of the while constructs, and indeed, they are quite more elegant - but, after calculating the overhead (and losen flexibility) when working with range/xrange, and while loops, you get to the conclusion that it isn't really worth using range/xrange loops. I'd like to show some examples and I'll be glad if someone can suggest some other fixes than while a loop :-) a) range overfllow : for i in range(0, 1 << len(S)) : . OverflowError: range() result has too many items ok, so we fix this one with xrange ! b) xrange long int overflow : for i in xrange(0, 1 << len(S)) : OverflowError: long int too large to convert to int Next thing I miss is the flexibility as in C for loops : for (i = 0; some_function() /* or other condition */ ; i++) or, for (i = 0 ; i < 10 ; i++) i = 10; I don't think range/xrange sucks, but I really think there should be some other constructs to improve the looping flexibility. Other thing may be, that I just miss an equally elegant alternative that's why I'd like to hear some suggestions on how to fix the above issues.. (btw, I've already browsed the archives related to my issue,but i don't see any good solution) Thanks Jernej. -- http://mail.python.org/mailman/listinfo/python-list
Parallelizing python code - design/implementation questions
Hello! I'm about to parallelize some algorithm that turned out to be too slow. Before I start doing it, I'd like to hear some suggestions/hints from you. The algorithm essentially works like this: There is a iterator function "foo" yielding a special kind permutation of [1,n]. The main program then iterates through this permutations calculating some proprieties. Each time a calculation ends, a counter is incremented and each time the counter is divisible by 100, the current progress is printed. The classical idea is to spawn m threads and use some global lock when calling the instance of the iterator + one global lock for incrementing the progress counter. Is there any better way? I'm especially concerned with performance degradation due to locking - is there any way to somehow avoid it? I've also read about the `multiprocessing' module and as far as I've understood : permutation = foo() threadlst = [] for i in xrange(m) : p = Process(target=permutation.next) threadlst.append(p) p.start() for p in threadlst: p.join() should do the trick. Am I right? Is there any better way other than this? -- http://mail.python.org/mailman/listinfo/python-list
