![]() |
|
Re: ** Python Support Thread **
i am trying tree.xpath("//{http://odds.sbrforum.com}side-name"), and root.xpath("//{http://odds.sbrforum.com}side-name"), tree.xpath("//{http://odds.sbrforum.com}:side-name"), and root.xpath("//side-name")
none work |
Re: ** Python Support Thread **
when i try to grab some random element and do tree.getpath(random_element) it gives me bull**** paths like /*/*[1]
what the hell is that |
Re: ** Python Support Thread **
Quote:
Code:
def avgspread(sp,lt): |
Re: ** Python Support Thread **
taking the MIT python course and came across this:
self.viruses = [x for x in newViruses] can someone please explain to me how this is better than a typical for loop. I'm also uncertain as to what this does |
Re: ** Python Support Thread **
That's called a list comprehension. In this case it's just copying the list. The equivalent as a for would be:
Code:
self.viruses = [] |
Re: ** Python Support Thread **
what do __lt__ and __eq__ do? I keep getting examples when i google but not an explanation. basically im confused as to how a class can return more than one thing using these fuctions.
|
Re: ** Python Support Thread **
How much do you know about classes? Those are for operator overloading ('<' and '==', respectively).
|
Re: ** Python Support Thread **
Quote:
For example in the below code, I'm manually copying a list with 1000 items and then doing the same operation with a list comprehension. The list comprehension is about 2.5x faster to do the exact same operation. Code:
import timeitCode:
Manual copy: 16.9621839523 |
Re: ** Python Support Thread **
Same benchmark with PyPy please :)
|
Re: ** Python Support Thread **
Same code in pypy 1.9
Output in seconds, lower is better: Code:
Manual copy: 5.08202004433Of course one of the reasons for this is list comprehensions are much less flexible than for loops. But the general rule is that if you are doing something simple that can be a list comprehension, it should be a list comprehension. However, if you try to cram something too complicated into a list comprehension it can get really gnarly and unreadable, and at that point you should probably just use a for loop for readability. There was a python style rule where I used to work that if your list comprehension was longer than 2 lines (80 character width), then it was too complicated and needed to be refactored somehow. |
Re: ** Python Support Thread **
Code:
Manual copy: 13.7768809795 |
Re: ** Python Support Thread **
List comprehensions that aren't super complicated are a lot easier to read than loops as well imo
|
Re: ** Python Support Thread **
Quote:
Manual copy: 10.962864498256714 List comprehension: 3.4187096686791882 |
Re: ** Python Support Thread **
What's that got, a 5x5 resolution screen... :)
|
Re: ** Python Support Thread **
So I'm getting a syntax error here for month in the third line...not sure why:
month = int(input("Please give me an integer for the month: ")) day = int(input("Please give me an integer for the day of the month: ")) # Now we test that the input date is during the 2011-2012 academic year and # is valid (e.g. 1/37 is not a valid date). If month == 9 and day == 4: print("This date is not during the academic year") Elif month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12 and day < 1 or day > 31 print("This date is invalid") Elif month == 4 or month == 6 or month == 9 or month == 11 and day < 1 or day > 30 print("This date is invalid") Anyone know why? |
Re: ** Python Support Thread **
are you actually capitalizing if and elif? that isnt' allowed
|
Re: ** Python Support Thread **
Ah, I'm ******ed. Also, is there an efficient way to do this:
Elif month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12 and day < 1 or day > 31 print("This date is invalid") What I'm trying to get it to do is: If month == 1 and day < 1 OR month ==1 and day > 31 OR month == 3 and day < 1... Know what I mean? Thanks again for the help. |
Quote:
Code:
If month in (3, 5, 7,) and (day < 1 or 31 < day): |
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
perfect, thanks a lot man. one last thing: is there a good place to go over these exercises? my book only has super basic ones...
thanks again. |
Re: ** Python Support Thread **
So I'm getting a good feel for python now. I would still like to be more familiar with all the popular packages and modules. What should I be getting familiar with? sys,os,itertools,etc...
|
Re: ** Python Support Thread **
Unittest
Numpy Scipy Django Functools(!) Tornado Good luck! |
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
Thanks a lot, Neko.
|
Re: ** Python Support Thread **
Quote:
done with these yet? i can suggest more when you're ready! ;) |
| All times are GMT -4. The time now is 03:50 PM. |
|
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 2008-2020, Two Plus Two Interactive