Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Sander Sweers
2010/1/13 Albert-Jan Roskam > > Interesting. Can this also be used to make sorting of alphanumerical list > items in a 'numerical' way easier? > >>> x > ['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6', > 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12']

Re: [Tutor] Future Appointments...

2010-01-31 Thread Sander Sweers
On 31 January 2010 16:40, Ken G. wrote: > Below is a program to determine when my next appointment is.  Line numbers > are provided for reference only. > > 01  import time, datetime, sys > 02  from datetime import date > 03  today = date.today() > 04  print > 05  print "Today date is:", today > 06

Re: [Tutor] query

2010-01-31 Thread Sander Sweers
On 31 January 2010 22:21, invincible patriot wrote: > can any one tel me how can i do indexing of individual characters in python > like if i hav a word eg david > a='david' > b=list(a) > # this will give ['d','a','v','i','d'] > not i want to print the index of each character > how can i do that >

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Sander Sweers
On do, 2010-02-04 at 13:30 -0500, Serdar Tumgoren wrote: > Could you all indulge me one last time and tell me if the above > version works for you? If so, I'll update the recipe to spare others a > similar headache. It now works ok but.. You should not use ord as variable as ord() is used by pyth

Re: [Tutor] Simple variable type question

2010-02-05 Thread Sander Sweers
On vr, 2010-02-05 at 16:54 +, Antonio de la Fuente wrote: > http://openbookproject.net/thinkcs/python/english2e/ch05.html > > exercise number 3 (slope function) and when I run it: > > python ch05.py -v > > the doctest for the slope function failed, because is expecting a > floating point val

Re: [Tutor] Simple variable type question

2010-02-05 Thread Sander Sweers
On vr, 2010-02-05 at 20:39 +, ALAN GAULD wrote: > return float(x1-y1)/(x2-y2) Does not work properly in version 2. Example is the 3rd doc test: float((3-2)/(3-1)) gives 0.0 instead of 0.5. Greets Sander ___ Tutor maillist - Tutor@python.org To u

Re: [Tutor] datetime a.m. not AM

2010-02-08 Thread Sander Sweers
On ma, 2010-02-08 at 13:02 -0800, bevan j wrote: > data = '1/09/1978 1:00:00 a.m.' If you know this will always be in the form of 'a.m.' you can replace it with 'am' by data.replace('a.m.','am'). Greets Sander ___ Tutor maillist - Tutor@python.org T

Re: [Tutor] rstrip in list?

2010-02-09 Thread Sander Sweers
On Tuesday 09 February 2010 16:28:43 Ken G. wrote: > ['102\n', '231\n', '463\n', '487\n', '555\n', '961\n'] > > I was using 'print mylist.rstrip()' to strip off the '\n' > > but kept getting an error of : > > AttributeError: 'list' object has no attribute 'rstrip' A string has attribute rstrip

Re: [Tutor] Shelve

2010-02-11 Thread Sander Sweers
On do, 2010-02-11 at 10:09 -0600, Randy Raymond wrote: > I am running Python 2.6.4 under Windows Vista 32-bit Home Edition. > When I run: > > import shelve > test=shelve.open("myTest.fil") And to shich directory does this file get written? I suspect you are writing to a protected directory. When

Re: [Tutor] command error

2010-02-16 Thread Sander Sweers
On 16 February 2010 21:32, Shurui Liu (Aaron Liu) wrote: > Here is a program I wrote, I don't know why I cannot exit when I tried 10 > times? Hope somebody can help me. Thank you! > > while (guess != the_number): >     if (guess > the_number): >     print ("Lower...") >     print ("You wer

Re: [Tutor] datetime, time zones, and ISO time

2010-02-17 Thread Sander Sweers
On 17 February 2010 22:37, David Perlman wrote: > As far as I can tell, this should always work.  So wouldn't it be nice if > there were a less convoluted way to get this?? There is pytz [1] which should provide a simpler way to manage timezone info in python. Greets Sander [1] http://pytz.sour

Re: [Tutor] Why is the max size so low in this mail list?

2010-03-01 Thread Sander Sweers
On 1 March 2010 18:13, Wayne Watson wrote: > See Subject. 40K here, but other Python lists allow for larger (total) > sizes. Don't know but if it is that long use pastebin [1]. Greets Sander [1] http://python.pastebin.com/ ___ Tutor maillist - Tutor

Re: [Tutor] Bowing out

2010-03-03 Thread Sander Sweers
On 3 March 2010 14:17, Kent Johnson wrote: > After six years of tutor posts my interest and energy have waned and > I'm ready to move on to something new. Let me join the other people and thank you for your contribution to this list. Good luck with something new :-) Greets Sander ___

Re: [Tutor] Encoding

2010-03-03 Thread Sander Sweers
On 3 March 2010 20:44, Giorgio wrote: s = "ciao è ciao" print s > ciao è ciao s.encode('utf-8') > Traceback (most recent call last): >   File "", line 1, in >     s.encode('utf-8') > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 5: > ordinal not in range(128)

Re: [Tutor] Encoding

2010-03-03 Thread Sander Sweers
On 3 March 2010 22:41, Sander Sweers wrote: > It is confusing but once understand how it works it makes sense. I remembered Kent explained it very clear in [1]. Greets Sander [1] http://mail.python.org/pipermail/tutor/2009-May/068920.html ___ Tu

Re: [Tutor] SQLite error messages

2010-03-09 Thread Sander Sweers
- Original message - > I am using the sqlite3 module with Python 3.1, and have some code which > goes something like as follows... > > import sqlite3 > con = sqlite3.connect('MyDatabase.db') > > try: >        execresult = con.execute('INSERT INTO MyTable (field_name) VALUES > ("MyValue")')

Re: [Tutor] SQLite error messages

2010-03-10 Thread Sander Sweers
On 10 March 2010 21:02, Alan Harris-Reid wrote: > Maybe I have misunderstood you, but I always thought that the 'finally' > section was run even if the 'try' section is successful, in which case I > would not want a rollback. I was thinking something like this. import sqlite3 con = sqlite3.conne

Re: [Tutor] Escaping a single quote mark in a triple quoted string.

2010-03-13 Thread Sander Sweers
On 13 March 2010 18:33, Ray Parrish wrote: > Hello, > > I am getting the following - > String = """http://www.rayslinks.com";>Ray's Links""" String > 'http://www.rayslinks.com";>Ray\'s Links' > > Note the magically appearing back slash in my result string. It is not really there. When y

Re: [Tutor] subprocess

2010-03-27 Thread Sander Sweers
On 27 March 2010 09:30, David Abbott wrote: > Here is an example using subprocess.call > http://dwabbott.com/code/index8.html > > and some more here with subprocess.Popen > http://asterisklinks.com/wiki/doku.php?id=wiki:subprocess On top of that we have the excelent PyMOTW from Doug on subprocess

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Sander Sweers
On 12 April 2010 18:28, Dotan Cohen wrote: > However, it fails like this: > $ ./moveUp.py > Traceback (most recent call last): >  File "./moveUp.py", line 8, in >    os.rename(f, currentDir) > TypeError: coercing to Unicode: need string or buffer, tuple found os.rename needs the oldname and the

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Sander Sweers
On 12 April 2010 22:13, Dave Angel wrote: > When combining directory paths, it's generally safer to use > > os.path.join() As KDE/Dolphin runs on windows this is even more important as it will sort out the directory separator (/ vs \) for you. Some added reading on os.path can be found on Doug's

Re: [Tutor] Problem iterating over csv.DictReader

2010-04-26 Thread Sander Sweers
On 26 April 2010 15:00, Matthew Williams wrote: > What I'm looking for is a way to explicity reset the iterator, to tell it to > go back to the beginning. You will need to use the seek method on the fileobject. f = open('insert your csv file here.csv', 'rb') #Note the b in 'rb' #Do your process

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread Sander Sweers
On 26 April 2010 21:38, C M Caine wrote: > Why does this not work: L = [' foo ','bar '] for i in L: >     i = i.strip() str.strip() _returns_ a *new* string and leaves the original string alone. The reason being that string are immutable so can not be changed. >>> s1 = ' foo ' >>> s1[1

Re: [Tutor] writing csv files

2010-05-22 Thread Sander Sweers
On 22 May 2010 09:46, prasad rao wrote: >  csvw=csv.writer(open('/home/prasad/kkm','w'), > dialect='excel',fieldnames=names) > Traceback (most recent call last): >  File "", line 1, in > TypeError: 'fieldnames' is an invalid keyword argument for this function fieldnames is part of the dictreader

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Sander Sweers
2010/5/28 spir ☣ : > his is a different feature from preserving *input* order of of keys, or of > key:value pairs. In Python 2.7 and 3.1 [1] we now have the OrderedDict which does preserve input order. Greets Sander [1] http://www.python.org/dev/peps/pep-0372/ __

Re: [Tutor] parse text file

2010-06-03 Thread Sander Sweers
On 3 June 2010 21:02, Colin Talbert wrote: > I couldn't find any example of it in use and wasn't having any luck getting > it to work based on the documentation. Good examples of the bz2 module can be found at [1]. greets Sander [1] http://www.doughellmann.com/PyMOTW/bz2/

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Sander Sweers
On 11 June 2010 15:57, Ken G. wrote: > In any event, if a number is listed more than once, I would like to know how > many times, such as 2 or 3 times.  For example, '3' is listed twice within a > list. If you do not have top keep the order of the number this will work. >>> a = [1, 2, 3, 3, 4] >

Re: [Tutor] Linux webcam libraries?

2010-06-13 Thread Sander Sweers
On 12 June 2010 20:22, Wayne Werner wrote: > I want to be able to grab a webcam image via python. So I'm curious if > anyone has had any experience/luck in this particular area and/or knows of > any libraries I should take a look at. I know my webcam definitely works > under linux because I can us

Re: [Tutor] Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

2010-06-24 Thread Sander Sweers
- Original message - > On Fri, 25 Jun 2010 04:51:13 am Lie Ryan wrote: > > On 06/24/10 02:10, pyt...@bdurham.com wrote: > > > Can someone confirm that Python 2.6 ftplib does *NOT* support > > > Unicode file names? Or must Unicode file names be specially > > > encoded in order to be used wit

Re: [Tutor] raw_input

2010-07-05 Thread Sander Sweers
On 5 July 2010 17:40, Shashwat Anand wrote: > use input() instead of raw_input() in Python3.x To add to this, in Python 2 we had input() [1] (unsafe for most uses) and raw_input() [2] (safe). Python 3 removed the old input() and renamed raw_input() to input() [3,4]. Greets Sander [1] http://doc

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Sander Sweers
On 5 July 2010 19:54, Vineeth Rakesh wrote: > Can some one help me to return a special pattern from a list. > > say list = > ["something1.mp3","something2.mp3","something4.pdf","something5.odt"] > > now say I just need to return the files with .mp3 extension. How to go about > doing this? Use os.

Re: [Tutor] subprocess output

2010-07-28 Thread Sander Sweers
- Original message - > I'm using Python 2.6.5 and I've got a challenge with the subprocess > module. I'd like the output to be stored in a variable, and not sent to > the stdout. The relevant lines as they are now: Go to google, enter "pymotw subprocess" and hit I am feeling lucky ;-) gre

Re: [Tutor] string to list

2010-08-05 Thread Sander Sweers
On 5 August 2010 06:38, Vikram K wrote: > Suppose i have this string: > z = 'AT/CG' > > How do i get this list: > > zlist = ['A','T/C','G'] If you know the format of the string is always the same you can do something like this. This fails when you have strings that do not have the '/' in the midd

Re: [Tutor] modify csv textfile

2010-08-07 Thread Sander Sweers
On 7 August 2010 04:35, TGW wrote: > I have a pipe delimited text file with 5 columns which looks like this: > 12345|some text|some more text|example125 oo3 3456|example32423 > 11223|more text|and more|example/73d 77665|example455667 > 12677|text|more|anotherexample 123|anotherexample45 > > What I

Re: [Tutor] modify csv textfile

2010-08-07 Thread Sander Sweers
On 7 August 2010 13:45, TGW wrote: >> You can test if one item in your list begins with example like: >> ' example125 oo3 3456'.lstrip()[:7].lower() == 'example' > > I think I need to use regex here. Perhaps you will agree. You could but you don't have to, consider this. r = '1234|Avail|53|Potat

Re: [Tutor] Performance list vs. deque for [-1]

2010-08-12 Thread Sander Sweers
On 12 August 2010 09:44, Alan Gauld wrote: >> I'm wondering what's the fastet datatype in python to lookup the last >> element in an ordered collection. > > When in doubt timeit() Out of curiosity I used timeit and lists are faster if we iterate over them one by one. Now this is my first go with

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Sander Sweers
On 12 August 2010 10:40, Evert Rol wrote: a = "my file number" a.replace(' ', '\\ ') > 'my\\ file\\ number' What if a has more than 1 space between words? Then I think this would be a safer way. >>> print "\\ ".join("my file number".split()) my\ file\ number Greets Sander __

Re: [Tutor] Performance list vs. deque for [-1]

2010-08-12 Thread Sander Sweers
On 12 August 2010 12:07, Sander Sweers wrote: > Deque took 0.009195 seconds > 693.01178383827209 / 10 (default times run by timeit) Messed up the deque results :( Deque took 0.009195 seconds 919.49732708930969 / 10 (default times run by timeit) Greets

Re: [Tutor] Multiple file open

2010-08-18 Thread Sander Sweers
On 18 August 2010 17:14, nitin chandra wrote: > I am on Python 2.6 > > Please guide with the syntax. All beginners tutorials on the web teach the syntax of python.. I am unsure what your questions is. > below is the existing program with Formula A (Mean). Formula B will be > Extrapolation, > a

Re: [Tutor] Adding all numbers in a file or list

2010-08-23 Thread Sander Sweers
On 23 August 2010 17:13, aug dawg wrote: > Is there a command or module that I can use to add all the items in a list? > Alternatively, is there one I can use to add all the numbers in a file? sum() is what you are looking for [1]. Greets Sander [1] http://docs.python.org/library/functions.html

Re: [Tutor] Adding all numbers in a file or list

2010-08-23 Thread Sander Sweers
On 23 August 2010 17:24, aug dawg wrote: > So it's sum(list_name) ? Correct, but it is not limited to lists. Any itterable with ints/floats will do, for example a tuple is also accepted. Greets Sander PS: Please use reply to all so others on this list may benefit from the questions/answers ;-)

Re: [Tutor] Controlling a device with ioctl's?

2010-08-24 Thread Sander Sweers
On 25 August 2010 00:04, Joe Veldhuis wrote: > Hello to all. I'm working on writing a tool that will control a piece of > hardware using ioctl's on its device node. Specifically, I'm trying to > configure and tune a DVB-S receiver on Linux. > > Just for starters, I want to try opening the fronte

Re: [Tutor] more on wx and tiff

2010-08-27 Thread Sander Sweers
On 27 August 2010 18:25, Albert-Jan Roskam wrote: > First, thanks for your previous replies. I cannot use IrfanView any time > soon, nor will my boss switch to Linux. Why not use graphicsmagick [1] which also provides a windows binary [2]. You can execute it with the subprocess [3] module? Greet

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Sander Sweers
On 4 September 2010 19:14, Bill Allen wrote: > Say I have and iterable called some_stuff which is thousands of items in > length and I am looping thru it as such: > > for x in some_stuff > etc... > > However, what if I want only to iterate through only the first ten items of > some_stuff, for

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Sander Sweers
On 4 September 2010 19:25, Sander Sweers wrote: > for x in some_stuff: >    if x <= 10: >        print x >    else: >        break Oops, corrected version... count = 0 for x in some_stuff: if count < 10: print x count +=1 else:

Re: [Tutor] exercise correct ??

2010-09-06 Thread Sander Sweers
On 6 September 2010 19:32, Roelof Wobben wrote: > def index_of(val, seq, start=0): >     """ >   >>> index_of(9, [1, 7, 11, 9, 10]) >   3 >   >>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5)) >   3 >   >>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4) >   6 >   >>> index_of('y', '

Re: [Tutor] exercise correct ??

2010-09-06 Thread Sander Sweers
On 6 September 2010 22:28, Roelof Wobben wrote: > As far as I know index is not a part of tuple so I have to convert it to a > list so I can use index. As of version 2.6/3 a tuple does have index(). Not sure which version you are using. Greets Sander _

Re: [Tutor] exercise correct ??

2010-09-06 Thread Sander Sweers
On 6 September 2010 21:45, Sander Sweers wrote: >> Is the exercise here wrong ? > > Looks like it, or it's a typo. Now that I had a better look the test is correct. Now it is up to you to figure out why your index_of() fails. Walter gave you a good hin

Re: [Tutor] slicing a string

2010-09-06 Thread Sander Sweers
On 7 September 2010 00:14, lists wrote: > Assuming that mytext is "test", I've found that mytext[-1:-4:-1] > doesn't work (as I expected it to) but that mytext[::-1] does. > > While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? How does it not "work"? What did you expect to happ

Re: [Tutor] FW: wierd replace problem

2010-09-14 Thread Sander Sweers
- Original message - > Look at the backslash! It doesn't strip the backslash in the string, but > it escapes the double quote following it. > > I don't know how people can explain it any better. Maybe the link below makes it clear what backslash really does. http://pythonconquerstheuni

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Sander Sweers
On 27 September 2010 22:00, Alex Hall wrote: > That makes sense. Basically, the * operator in this case acts as a > copying command. For simple data types this is fine, but throw in a > complex type, in this case a list (though I expect that any object > would do this) and you are just doing what

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Sander Sweers
On 27 September 2010 23:15, Sander Sweers wrote: >> objects: copying the memory location, not making a deep copy and >> getting a duplicate object. > > It does not copy the object it makes multiple _references_ to the *same* > object. Oops, You already got the idea and I sh

Re: [Tutor] using "in" with a dictionary

2010-09-28 Thread Sander Sweers
On 28 September 2010 23:58, Alex Hall wrote: > Hi all, yet again: > I have a dictionary that will look something like: > d={ >  (1,2):"a", >  (3,4):"b" > } > > How can I say: > if (1,2) in d: print d[(1,2)] This will work fine. > This is false Not it is not.. >>> d = {(1,2):"a",(3,4):"b"} >>> (

Re: [Tutor] Using contents of a document to change file names, (was Re: how to extract data only after a certain ...)

2010-10-12 Thread Sander Sweers
On 12 October 2010 21:15, Joel Goldstick wrote: > When the dictionary is retrieved, its order depends on the hashed values > rather than the keys themself. If (big IF here) you really need an ordered dict you can use the OrderedDict from the collections module. However this will only guarantee *i

Re: [Tutor] Converting from unicode to nonstring

2010-10-14 Thread Sander Sweers
On 14 October 2010 16:14, David Hutto wrote: > (u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10') > > Which is a tuple of unicode strings. From this I > need to place portions of the tuple into other fields, > but not as unicode strings, but literals no ''. > > For example if

Re: [Tutor] Converting from unicode to nonstring

2010-10-14 Thread Sander Sweers
On 14 October 2010 20:29, David Hutto wrote: > Actually, I needed it to be converted to something without a string > attached to it. See a post above, and it was fixed by eval(), Using eval is a big security risk and is generally not recommended for any production code. What do you think eval() r

Re: [Tutor] Converting from unicode to nonstring

2010-10-14 Thread Sander Sweers
On 14 October 2010 21:02, Sander Sweers wrote: > If you really want (you really don't) to use eval() then at least use Oops, hit send to soon. "(you really don't)" should have been "(you really don't need to use it)". Greets Sander

Re: [Tutor] Requesting restricted URL (further authentication requested)

2010-10-19 Thread Sander Sweers
On 19 October 2010 21:56, Tim Johnson wrote: > I've written the following function which successfully gets an > authenticated URL: > def getRestrictedURL(authName,URL,log,pswd): >        auth_handler = urllib2.HTTPBasicAuthHandler() >        auth_handler.add_password(authName, URL,log,pswd) >    

Re: [Tutor] What does "TypeError: 'int' object is not iterable" mean?

2010-10-21 Thread Sander Sweers
On 21 October 2010 18:09, Richard D. Moores wrote: > In case anyone's interested, the script now works the way I wanted: > . It should work for anyone > with 2.6 or 2.7 > > I'd appreciate constructive criticism. Instead of all the zeros2float craziness use s

Re: [Tutor] Need help with converting script using 2.6's urllib2 to Python 3.1

2010-10-25 Thread Sander Sweers
On 25 October 2010 14:46, Richard D. Moores wrote: > I'd like to convert the script to 3.1, but I can't understand the docs > for the 3.1 urllib module. Please someone tell me what to do. > (Converting   'print rate'   to   'print(rate)'   I understand.) Have you actually tried reading the docume

Re: [Tutor] Need help with converting script using 2.6's urllib2 to Python 3.1

2010-10-25 Thread Sander Sweers
On 25 October 2010 18:19, Richard D. Moores wrote: > Doing it your way, > > from urllib import request > a = > request.urlopen('http://www.marketwatch.com/investing/currency/CUR_USDYEN').read(20500) > print(a[123:140]) > > succeeds. Why? Not sure how this exactly works but this is what I know. T

Re: [Tutor] Converting a numerical variable into a string variable

2009-02-12 Thread Sander Sweers
On Thu, Feb 12, 2009 at 21:06, Andres Sanchez wrote: > Please, give me a hand with this. Say I have a vector defined as > x=[1,2,3,4,...,9]. I need to write string variables with the names > G1BF...G9BF. Thus, the first string variable would be 'G'+'1'+'BF', being > the number 1 equal to x[0]. Now

[Tutor] print function in python 2.6 and 3

2009-02-12 Thread Sander Sweers
Hello, I see more people posting answers with the new print() function only available in python 3 and in python 2.6 via an import from __future__. Now I am not confused by this but I can understand that people very new to python can get confused byt this. Especially people following a guide online

Re: [Tutor] print function in python 2.6 and 3

2009-02-12 Thread Sander Sweers
On Thu, Feb 12, 2009 at 22:50, Alan Gauld wrote: >> Now what should be used and promoted on the list? > > We can't shouldn't promote one over the other since the remit > of this list is to help newbies, regardless of the Python version. OK, understood. > The only thing I would strongly request i

Re: [Tutor] urllib unquote

2009-02-16 Thread Sander Sweers
On Mon, Feb 16, 2009 at 14:12, Norman Khine wrote: > Type "help", "copyright", "credits" or "license" for more information. import base64, urllib data = 'hL/FGNS40fjoTnp2zIqq73reK60%3D%0A' data = urllib.unquote(data) print base64.decodestring(data) > ???Ը???Nzv̊??z?+? > >

Re: [Tutor] urllib unquote

2009-02-17 Thread Sander Sweers
On Tue, Feb 17, 2009 at 08:54, Norman Khine wrote: > Thank you, but is it possible to get the original string from this? You mean something like this? >>> urllib.quote('hL/FGNS40fjoTnp2zIqq73reK60=\n') 'hL/FGNS40fjoTnp2zIqq73reK60%3D%0A' Greets Sander ___

Re: [Tutor] Converting "HH:MM:SS" to datetime

2009-03-01 Thread Sander Sweers
2009/3/1 Wayne Watson : > Ok, how do I do what's mentioned in Subject? Googling for python and time gives as first result. http://www.doughellmann.com/PyMOTW/datetime/index.html Which covers all you need to know to solve this. Greets Sander ___ Tutor

Re: [Tutor] Converting "HH:MM:SS" to datetime

2009-03-01 Thread Sander Sweers
2009/3/1 Sander Sweers : > > Googling for python and time gives as first result. Sorry this is not correct, ignore it. Greets Sander ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Convert XML codes to "normal" text?

2009-03-04 Thread Sander Sweers
2009/3/4 Eric Dorsey : > d = feedparser.parse('http://snipt.net/dorseye/feed') > > x=0 > for i in d['entries']: >     print d['entries'][x].title >     print d['entries'][x].summary >     print >     x+=1 > > Output > > Explode / Implode List > >>> V = list(V) > I know, for example, that the > c

Re: [Tutor] could someone explain why this happens to me.

2009-03-07 Thread Sander Sweers
2009/3/7 Alan Gauld : >> mycopy = original[:] > > Returns a slice of the original list. In this case it so happens > the slice is the full list. > >> mycopy = list(original) > > Use the list type constructor to make a list out of its argument. > It just so happens the argument in this case is a lis

Re: [Tutor] creating new dictionary based on membership testing

2009-03-09 Thread Sander Sweers
2009/3/9 A.T.Hofkamp : > You can do something like > [d for d in d1 if d['is_selected'] == False] > to get your dicts. > > If 'is_selected' is not always present, it gets a bit more complicated, I'll > leave that as an exercise for the interested reader :) You would use d.get('is_selected', False)

Re: [Tutor] memory error files over 100MB

2009-03-10 Thread Sander Sweers
2009/3/10 Alan Gauld : >>           newFile.write(zf.read(zfilename)) > > Remember you are reading the file into memory and then writing it > out again in a single operation, that will use twice the space of the > uncompressed files - plus some extra for overhead. Question, Do you mean the file in

Re: [Tutor] incrementing one minute

2009-03-30 Thread Sander Sweers
2009/3/30 pa yo : > I need to add one minute to a string that has a date and a time in > MMDDHHMM format. > e.g:  200903281346 should become 200903281347 > > the following script converts the string into time and adds one > minute; but somehow I also add an hour and I don't understand why. > >

Re: [Tutor] os.popen3 > subprocess.Popen but nohup.out won't go

2009-04-04 Thread Sander Sweers
2009/4/4 dave selby : > os.popen3('nohup %s/core/kmotion_hkd2.py &> /dev/null &' % kmotion_dir) > > becomes .. > > subprocess.Popen('nohup %s/core/kmotion_hkd2.py &> /dev/null &' % > kmotion_dir, shell=True) > > all is well except I now get > > nohup: appending output to `nohup.out' > > on the term

Re: [Tutor] os.popen3 > subprocess.Popen but nohup.out won't go

2009-04-04 Thread Sander Sweers
2009/4/4 Sander Sweers : Bah, of course you need to open the files writable :-( This > outfile = open('/tmp/myoutfile') > errfile = open('/tmp/myerrfile') Should be outfile = open('/tmp/myoutfile', 'w') errfi

Re: [Tutor] Append a dictionary value

2009-04-04 Thread Sander Sweers
2009/4/4 David : > I put together a todo program here; > http://linuxcrazy.pastebin.com/f74beaf78 > > And I am trying to add an option to edit the values which are date and time. > Below I have gotten this far but now I need some help. looks like my attempt > to use setdefault will not work. Please

Re: [Tutor] Please use plain text.

2009-04-07 Thread Sander Sweers
2009/4/7 Wayne Watson : > What I would consider a big difficulty with flat text is exactly that it is > flat. There are lots of times, in my experience, when a graphic, > particularly captured ones, can lead to much faster and smarter solution. I > think this list may allow them, but it seems at a

Re: [Tutor] ideas on how to process a file

2009-04-10 Thread Sander Sweers
2009/4/10 Spencer Parker : > The question is now...what do I do to find duplicate entries in the text > file I am reading.  I just want to filter them out.  There are a ton of > duplicate entries in there. >>> for line in text_file: # No need for readlines(), a file is iterable >>>  if 'FULLNAME

[Tutor] Make beautifulsoup show the data it has an issue with

2009-04-10 Thread Sander Sweers
Hello Tutors, I am having some issues with a malformed tag in a html page. BeautifulSoup barfs with the following. raceback (most recent call last): File "", line 1, in tsoup = BeautifulSoup(readPage('http://url.sanitized')) File "C:\Python25\lib\site-packages\BeautifulSoup.py", line 149

Re: [Tutor] How to programmatically EDIT a python file using an editorof my choice ?

2009-04-12 Thread Sander Sweers
2009/4/12 Dominique : > I tried several other ways without any success: > subprocess.Popen(args = ["notepad++.exe", filename]) > subprocess.Popen(args = ["C:\Program Files\Notepad++\notepad++.exe", > filename]) Try this: subprocess.Popen(args = [r'C:\Program Files\Notepad++\notepad++.exe', filen

Re: [Tutor] Make beautifulsoup show the data it has an issue with

2009-04-12 Thread Sander Sweers
2009/4/10 Kent Johnson : > Or, catch > the exception, have the code find out where the error is and display > the bad line. This is what I was looking for. I know how to catch the exception but how do I make it display the bad line? Thanks Sander ___ Tu

Re: [Tutor] How to programmatically EDIT a python file using an editorof my choice ?

2009-04-12 Thread Sander Sweers
2009/4/12 Dominique : > With r before the path of the software, it works perfectly. > subprocess.Popen([r"C:\Program Files\Editra\Editra.exe", filename]) > I saw that once but I don't remember and cannot find the reason for the use > of r. The r means the string is a raw string. > I'll try not t

Re: [Tutor] Make beautifulsoup show the data it has an issue with

2009-04-12 Thread Sander Sweers
2009/4/12 Kent Johnson : > try: >  tsoup = BeautifulSoup(data) > except HTMLParseError, ex: Aah, ex is the object/class which has the error data. This was the missing piece for me. Many thanks Kent! Greets Sander ___ Tutor maillist - Tutor@python.org

Re: [Tutor] How to programmatically EDIT a python file using an editorof my choice ?

2009-04-13 Thread Sander Sweers
2009/4/13 Dominique : > What surprises me is that before calling the subprocess.Popen() method, I > normalized the path using: > filename = os.path.normpath(filename). It does.But do you also call os.path.normpath for the program path? See below an example. >>> import os >>> path = 'C:\Program Fi

Re: [Tutor] problem with a simple logger with RotatingFileHandler

2009-04-14 Thread Sander Sweers
2009/4/14 Daniel : > def get_logger(log_filename): >     my_logger = logging.getLogger("MyLogger") >     my_logger.setLevel(logging.debug) ^^^ You have a small typo. This should be in capitals, logging.DEBUG. Greets Sander

Re: [Tutor] code publishing

2009-04-16 Thread Sander Sweers
2009/4/16 spir : > I have no clue whether there is a common place to publish some (free like the > air) python source code for review, use, evolution... > (It's about 17 5kb.) Maybe http://python.pastebin.com is what you are looking for? Greets Sander

Re: [Tutor] Is it syntactic,semantic or runtime?

2009-04-25 Thread Sander Sweers
2009/4/25 prasad rao : > So opening blank Explorer after complaining th html file not found. > Where is the problem? There are typing errors on the below... > > def pp(): > @@@ import urllib > @@@ import subprocess > @@@ so=urllib.urlopen('http://www.asstr.org') > @@@ data=so.read() > @@@ de=op

Re: [Tutor] How to run a .py file or load a module?

2009-04-26 Thread Sander Sweers
2009/4/26 Dayo Adewunmi : > I'm looking at recursion in "Think Python", and this is the bit of code: > > #!/usr/bin/env python > > def countdown(n): >       if n <= 0: >               print 'Blastoff!' >       else:                 print n >               countdown(n-1) > > > I've typed that in vim

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Sander Sweers
2009/4/29 David : > Here is the whole program so far, what it does is it logs into a druple web > site and posts. I would like to make it better, as you can see I do the same > thing over and over. > > http://linuxcrazy.pastebin.com/m7689c088 What you can do is define all the variables upfront. Th

Re: [Tutor] Encode problem

2009-05-04 Thread Sander Sweers
2009/5/4 Kent Johnson : > str.decode() converts a string to a unicode object. unicode.encode() > converts a unicode object to a (byte) string. Both of these functions > take the encoding as a parameter. When Python is given a string, but > it needs a unicode object, or vice-versa, it will encode or

Re: [Tutor] Optparse question: if only certain values are acceptable

2009-05-08 Thread Sander Sweers
2009/5/9 Terry Carroll : > In otherwords, if the user enters: > >  progname -f X > > It runs, producing its output in format X.  Similar if "Y" or "Z" is > specified instead of "X". > > But if the user specifies > >  progname -f A > > I want it to spit up because A is not a recognized format. Is t

Re: [Tutor] Python popen command using cat > textfile .... how to terminate

2009-05-14 Thread Sander Sweers
Forwarding to list because of mail delivery error... 2009/5/15 Sander Sweers : > 2009/5/14 MK : >> i am using this code to send an "cat > ThisIsMyUrl" with popen. > > First, I am not sure if you understand what "cat > ThisIsMyUrl" > actually does...

Re: [Tutor] Python popen command using cat > textfile .... how to terminate

2009-05-15 Thread Sander Sweers
2009/5/15 MK : > Ok. I explain it once more. Its not about reading the console output of > the command. Its that i want to put a empty file in my subdirectories > so that the name of the file is a message or url or something else. > And if you want an empty file you can do that with > "cat > IAmAnE

Re: [Tutor] clean text

2009-05-19 Thread Sander Sweers
2009/5/19 spir : > def _cleanRepr(text): >        ''' text with control chars replaced by repr() equivalent ''' >        result = "" >        for char in text: >                n = ord(char) >                if (n < 32) or (n > 126 and n < 160): >                        char = repr(char)[1:-1] >  

Re: [Tutor] Can't print a string, gives me syntax error

2009-05-25 Thread Sander Sweers
2009/5/25 xbmuncher : > I ran this in IDLE: t = 'hi' print t > SyntaxError: invalid syntax (, line 1) What version of python are you using (I suspect version 3)? > I've also tried this as sample.py : > import string > text = 'hello world' > print text If you are using python 3 then the

Re: [Tutor] CVS File Opening

2009-05-26 Thread Sander Sweers
2009/5/26 Paras K. : > Hello, > > I have been working on this script / program all weekend. I emailed this > address before and got some great help. I hope that I can get that again! > > > First to explain what I need to do: > > Have about 6 CSV files that I need to read. Then I need to split based

Re: [Tutor] Displaying range in 3.0.1

2009-05-28 Thread Sander Sweers
2009/5/28 Gregory Morton : > I've been reading this Python 3.0.1 > tutorial(http://docs.python.org/3.0/tutorial/controlflow.html), and now I'm > stuck at the second example in 4.3. This is what the example says the output > should look like: No it doen't but I can understand the confusion. More in

Re: [Tutor] converting xls to csv

2009-06-06 Thread Sander Sweers
2009/6/6 Emile van Sebille : >> for f in files: >>    print f >>    csv.reader(open (f), delimiter=' ', quotechar='|') > > you open it here, but don't save a reference to the opened file.  Try... >      ff = csv.reader(open (f), delimiter=' ', quotechar='|') >    reader(...) >        csv_reader

Re: [Tutor] converting xls to csv

2009-06-06 Thread Sander Sweers
2009/6/6 Nick Burgess : > Is it posible to take > the regex compile from user input?  To make it take an argument,  like > >> csvSearch.py 10.192.55 You can use raw_inpout() see [1] for the docs user_input = raw_input('Please provide input') Greets Sander [1] http://docs.python.org/library/fun

Re: [Tutor] converting xls to csv

2009-06-07 Thread Sander Sweers
On Sun, 2009-06-07 at 00:54 +0200, Sander Sweers wrote: > 2009/6/6 Nick Burgess : > > Is it posible to take > > the regex compile from user input? To make it take an argument, like > > > >> csvSearch.py 10.192.55 > > You can use raw_input() see [1] for

  1   2   3   >