[Tutor] or synxtax in if statement
I think I want to be lazy and express this if a == b | a = c (if a equal b or a equals c) using if a == b | c it seems to work.. but I'm not sure if it is correct -- and I haven't seen any documentation on using this type of syntax. -- -- David Bear College of Public Programs at Arizona State University ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] unicode encoding hell
I'm using universal feed parser to grab an rss feed. I'm carefull not to use any sys.out, print, file write ops, etc, UNLESS I use a decode('utf-i') to convert the unicode string I get from feed parser to utf-8. However, I'm still getting the blasted decode error stating that one of the items in the unicode string is out range. I've checked the encoding from the feed and it does indeed say it is utf-8. The content-type header is set to application/rss+xml . I am using the following syntax on a feedparser object: feedp.entry.title.decode('utf-8', 'xmlcharrefreplace') I assume it would take any unicode character and 'do the right thing', including replacing higher ordinal chars with xml entity refs. But I still get UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 31: ordinal not in range(128) Clearly, I completely do not understand how unicode is working here. Can anyone enlighten me? -- David Bear College of Public Programs at Arizona State University ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] getting iteration level
Lets say I have a list object that I iterate over like this: for item in myList: process(item) During execution of the for loop something happens and I want to know how many items have be iterated over, how do I find out? Without resorting to some counter inside the loop, is there some python object I can ask? -- David Bear College of Public Programs at Arizona State University ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] appending to a list
I want to return a tuple from a function. I want to append the second element of that tupple to a list. For example mylist = [] def somefunc(): return(3.14, 'some string') somenum, mylist.append(??) somefunc() obviously, the syntax doesn't work. This should be easy, but I've never seen example code. any pointers? -- -- David Bear College of Public Programs at Arizona State University ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor