Re: [Tutor] Value Error

2013-06-12 Thread Sander Sweers
On 06/12/2013 10:49 PM, Jim Mooney wrote: > Raised when a built-in operation or function receives an argument that has > the right type but an inappropriate value, and the situation is not > described by a more precise exception such as > IndexError

Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Sander Sweers
On 04/17/2013 02:34 AM, eryksun wrote: > I just went through the steps. You don't even need your password. > Enter your email address in the bottom field of the list info page: > > http://mail.python.org/mailman/listinfo/tutor > > Click the button that says "Unsubscribe or edit options". Then sim

Re: [Tutor] oops - resending as plain text

2013-04-16 Thread Sander Sweers
On 04/16/2013 07:48 PM, Jim Mooney wrote: > I accidentally sent as HTML so this is a resend in case that choked > the mailing prog ;') > > I was doing a simple training prog to figure monetary change, and > wanted to avoid computer inaccuracy by using only two-decimal input > and not using divisio

Re: [Tutor] unicode help

2012-11-14 Thread Sander Sweers
Marilyn Davis schreef op wo 14-11-2012 om 13:23 [-0800]: > I found this site: > http://hints.macworld.com/article.php?story=20100713130450549 > > and that fixes it. Short answer: It is not a fix but a workaround. Try: print symbol.encode('utf-8') Longer answer: It is not really a fix, it is a wo

Re: [Tutor] Python and xml *creation*

2012-10-26 Thread Sander Sweers
Op vrijdag 26 oktober 2012 17:00:16 schreef Prasad, Ramit: > Based on the most recent comment (May 2010) I would probably > stick with online tutorials. I generally do not trust "reviews" on the publisher's website as they have been proved to be constructed by them. > Here are some tutorials fo

Re: [Tutor] Python and xml *creation*

2012-10-26 Thread Sander Sweers
Op zaterdag 27 oktober 2012 03:30:26 schreef Steven D'Aprano: > On 27/10/12 03:14, Sander Sweers wrote: > > Do any of you know of good online resources? I found an o'reilly book [1] > > do you know if it is any good? > > > > [1] http://shop.oreilly.com/produ

[Tutor] Python and xml *creation*

2012-10-26 Thread Sander Sweers
Hi List, I am looking for resources on creating xml files in python. I have found some resources but they all are very basic. I find lots of resources online about parsing and searching in an xml file but not so much about creating them. Do any of you know of good online resources? I found an o

Re: [Tutor] For - if - else loop; print selective output

2012-10-24 Thread Sander Sweers
Alan Gauld schreef op wo 24-10-2012 om 17:49 [+0100]: > I confess I'm not keen on the else part of a for loop and never use > it, > I think it leads to more confusion than anything. It doesn't do what > most folks seem to expect, it should probably be called 'end' or > something similar rather t

Re: [Tutor] extract uri from beautiful soup string

2012-10-14 Thread Sander Sweers
Sander Sweers schreef op ma 15-10-2012 om 02:35 [+0200]: > > On Mon, Oct 15, 2012 at 12:12 AM, Sander Sweers > > wrote: > > > Norman Khine schreef op zo 14-10-2012 om 23:10 [+0100]: > > Norman Khine schreef op ma 15-10-2012 om 00:17 [+0100]: > > i tried this: htt

Re: [Tutor] extract uri from beautiful soup string

2012-10-14 Thread Sander Sweers
Please don't top post. > On Mon, Oct 15, 2012 at 12:12 AM, Sander Sweers > wrote: > > Norman Khine schreef op zo 14-10-2012 om 23:10 [+0100]: > >> One thing is that when I try to write the assoc_data into a CSV file, > >> it groaks on > >> > &g

Re: [Tutor] extract uri from beautiful soup string

2012-10-14 Thread Sander Sweers
Norman Khine schreef op zo 14-10-2012 om 23:10 [+0100]: > One thing is that when I try to write the assoc_data into a CSV file, > it groaks on > > UnicodeEncodeError: 'ascii' codec can't encode character u'\xc7' in position > 0: It looks like python is doing an implicit decode/encode on one of y

Re: [Tutor] Through a glass, darkly: the datetime module

2012-10-07 Thread Sander Sweers
Roel Schroeven schreef op zo 07-10-2012 om 21:19 [+0200]: > Sander Sweers schreef: > > > > Op 7 okt. 2012 04:29 schreef > <mailto:aklei...@sonic.net>> het volgende: > > > I'm also not sure but I seem to remember that it is > > > ("SUNDAY&

Re: [Tutor] Through a glass, darkly: the datetime module

2012-10-07 Thread Sander Sweers
Op 7 okt. 2012 04:29 schreef het volgende: > I'm also not sure but I seem to remember that it is > ("SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", > "SATURDAY", "SUNDAY") > which I think is extremely clever because it gets around the problem > created by the fact that some peopl

[Tutor] Pragmatic Unicode, or, How do I stop the pain?

2012-07-19 Thread Sander Sweers
https://www.youtube.com/watch?v=sgHbC6udIqc This is a very good talk on Unicode which was done at PyCon US 2012. It helped me a lot to understand the pain. Greets Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription optio

Re: [Tutor] use the data None

2012-06-04 Thread Sander Sweers
On 4 June 2012 12:14, Tehn Yit Chin wrote: > The potential for the variable not to exists is when I am using the > optparser module, and I want to check if a particular parameter was passed > in or not. If the parameter was not passed in, then the variable would not > exists. Eg Optparse will alw

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Sander Sweers
On 17 February 2012 14:04, leam hall wrote: > My concern with variables is that they have to be passed in specific > order to the function, and they may have to have their type set > multiple times so that you can perform the right functions on them. In > a dict you could set it on insert and not

Re: [Tutor] regexp

2011-11-04 Thread Sander Sweers
On 5 November 2011 00:38, Dinara Vakhitova wrote: > Sorry, I didn´t know that I couldn´t ask questions about the homework... This list is meant to help with learning python and not to do homework assignments. So if you get stuck with something yes you can post it but be open about it and show wh

Re: [Tutor] Creating Android Apps w/ Python

2011-11-03 Thread Sander Sweers
On Thu,  3 Nov 2011, 06:12:58 CET, Mike Nickey wrote: > I am hoping that there is a Python ADK that will allow creation of > apps with Python but I haven't seen one and wanted to see what you know is > out there. Linux journal has an article on this [1]. I have no experience in this but it lo

Re: [Tutor] string immutability

2011-10-24 Thread Sander Sweers
On Mon, 24 Oct 2011, 20:04:20 CEST, Johan Martinez wrote: > I am struggling to understand Python string immutability. I am able to > modify Python string object after initializing/assigning it a value. So > how does immutability work? I am not following it. Sorry for really > stupid question. Any

Re: [Tutor] Using xml.etree

2011-09-19 Thread Sander Sweers
On 17/09/11 13:08, lists wrote: I have been trying to learn how to parse XML with Python and learn how to use xml.etree. Lots of the tutorials seem to be very long winded. I'm trying to access a UK postcode API at www.uk-postcodes.com to take a UK postcode and return the lat/lng of the postcode.

Re: [Tutor] Unusual pathfile

2011-09-13 Thread Sander Sweers
On Tue, 13 Sep 2011, 21:01:56 CEST, Alan Gauld wrote: > On 13/09/11 16:41, Susana Iraiis Delgado Rodriguez wrote: > > structure. About the indention for the code, I tried my best to make it > > clear ande neat. But the mi e-mail editor it's mixing-up spaces. > > OK, That's unfortunate. Which edi

Re: [Tutor] Calendar

2011-09-12 Thread Sander Sweers
On 12/09/11 21:15, nitin chandra wrote: I need to create a calendar with python& CSS for the web page, in the following format Dec , 2011 - sun | mon | tue | wed th

Re: [Tutor] reclassify values in an array

2011-09-01 Thread Sander Sweers
On Thu,  1 Sep 2011, 01:17:45 CEST, questions anon wrote: > Firstly just make them zeros and ones, for example if the values in the > array are less than 100 make them 0 and if greater than 100 make them 1. > And then finally sum them together. > I have attempted a few methods, see code below.

Re: [Tutor] Quote of the Day version 1.0

2011-08-31 Thread Sander Sweers
On 31 August 2011 21:14, Cranky Frankie wrote: > I made some headway on the quote of the day program. I just tried to > do it simple using two assumptions: > > - long quotes are going to print funny until I figure out the string > splitting stuff Define funny? Normally the linux console will wrap

Re: [Tutor] urllib2 issue getting realm

2011-08-31 Thread Sander Sweers
On 31 August 2011 14:27, Johan Geldenhuys wrote: > On 31/08/2011, at 22:09, Sander Sweers wrote: >> On 31 August 2011 09:46, Johan Geldenhuys wrote: >>> I am trying to use a very simple piece of code to get the realm from >>> different HTTPS URLs. >>> >&g

Re: [Tutor] urllib2 issue getting realm

2011-08-31 Thread Sander Sweers
On 31 August 2011 09:46, Johan Geldenhuys wrote: > I am trying to use a very simple piece of code to get the realm from > different HTTPS URLs. > > This realm is essential for successful authentication on the HTTPS session. I think you got 2 things mixed up, http authentication and encrypted http

Re: [Tutor] issues with urllib and loading a webpage

2011-08-24 Thread Sander Sweers
On Wed, 24 Aug 2011, 00:03:23 CEST, Robert Sjoblom wrote: > > > Are you using Python 3 and urllib, and not using httplib2? Because I > > > honestly can't get urllib.request.urlopen to work with > > > http://www.boursorama.com/ -- I only get b'' from there. > > > > Yes, Python 3.2 which version

Re: [Tutor] issues with urllib and loading a webpage.

2011-08-23 Thread Sander Sweers
On 23 August 2011 22:59, Robert Sjoblom wrote: > Are you using Python 3 and urllib, and not using httplib2? Because I > honestly can't get urllib.request.urlopen to work with > http://www.boursorama.com/ -- I only get b'' from there. Yes, Python 3.2 which version one are you using? I tried both w

Re: [Tutor] issues with urllib and loading a webpage.

2011-08-23 Thread Sander Sweers
On 23/08/11 21:27, Robert Sjoblom wrote: Here's the code I'm working with: from http.client import HTTPConnection HTTPConnection.debuglevel = 1 from urllib.request import urlopen url = "http://www.boursorama.com/includes/cours/last_transactions.phtml?symbole=1xEURUS"; response = urlopen(url) pr

Re: [Tutor] calculation in string operations

2011-08-03 Thread Sander Sweers
On 4 August 2011 01:16, David wrote: > I got an error message that surprises me. I know how to solve the > problem (couple of parentheses will do), but I would expect Python to > run as the code is presented below. > After all, my_weight is a number that can be multiplied by a float. > I would exp

Re: [Tutor] Copying Variables

2011-07-25 Thread Sander Sweers
On 25 July 2011 17:17, naheed arafat wrote: > I got a question in this context. > suppose > a={'a': 3, 'b': [1, 2], 5: 100} > --b=a --    vs-- > b=copy.copy(a) > > b[5]=6  

Re: [Tutor] Resend: Using pexpect to SCP files

2011-07-19 Thread Sander Sweers
On 19 July 2011 13:20, Johan Geldenhuys wrote: It works fine for me in an interactive idle session.. Have you tried this to see if works like this? Does the command work when run directly from the command line? > I am using pexpect in a script to SCP files to a inux server. > Here is a snippet f

Re: [Tutor] Floating point exercise 3 from Learn python the hard way

2011-06-14 Thread Sander Sweers
On 14 June 2011 15:20, amt <0101...@gmail.com> wrote: >>> But I can't understand at line 2 and 3. I mean it makes no difference >>> for me. Saying 30 or 30.0 is the same thing. >>> As well as saying 97 or 97.0. >> >> Precisely, thats why I asked the question. > > As a beginner at line 2 and 3 I see

Re: [Tutor] Clunky Password maker

2011-05-25 Thread Sander Sweers
On Wed, 25 May 2011, 19:25:59 CEST, Wolf Halton wrote: > [code] > def new_pass(): >        series = ['`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', > '=', \ >                            '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', >')', '_', > '+', \ >                         

Re: [Tutor] reading very large files

2011-05-17 Thread Sander Sweers
On Tue, 17 May 2011, 19:20:42 CEST, Vikram K wrote: > I wish to read a large data file (file size is around 1.8 MB) and > manipulate the data in this file. Just reading and writing the first 500 > lines of this file is causing a problem. I wrote: Unless you are very constrained memory wise 1.8 M

Re: [Tutor] Grouping based on attributes of elements in a List

2011-03-29 Thread Sander Sweers
On 30 March 2011 00:30, Alan Gauld wrote: > Wouldn't you just return a tuple of the two elements? > > Or am I missing something having jumped into the middle of the thread... Ah yes, you are correct. But imo reading "key=lambda l: (l[1], l[0], l[2])" (which would be needed to sort how the OP want

Re: [Tutor] Grouping based on attributes of elements in a List

2011-03-29 Thread Sander Sweers
2011/3/29 Rafael Durán Castañeda : > And more pythonic, I think I don't agree :-). I think itemgetter from the operator module is more flexible, readable and elegant than using a lamda. How would you sort on the first and last item with lambda? Greets Sander __

Re: [Tutor] Grouping based on attributes of elements in a List

2011-03-29 Thread Sander Sweers
On 29 March 2011 23:52, Sander Sweers wrote: > On 29 March 2011 22:03, ranjan das wrote: >> New_List=[ [ ( 'G1', 'CFS', 'FCL', 'R1' ), ('G1', 'CFS', 'FCL', 'R2' ), >> ('G4', 'CFS

Re: [Tutor] Grouping based on attributes of elements in a List

2011-03-29 Thread Sander Sweers
On 29 March 2011 22:03, ranjan das wrote: > List=[( 'G1', 'CFS', 'FCL', 'R1' ),('G3', 'LOOSEFREIGHT', 'MIXEDLCL', 'R9'), > ('G4', 'CFS', 'FCL', 'R10' ), ('G2',  'LOOSEFREIGHT', 'LCL', 'R4' ), ('G1', > 'CFS', 'FCL', 'R2' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R5')  ] > > > now I want to group this eleme

Re: [Tutor] Expanding a variable with subprocess on Windows

2011-03-07 Thread Sander Sweers
On Tue,  8 Mar 2011, 07:44:31 CET, Becky Mcquilling wrote: > gpg = 'c:/program files (x86)/gnu/gnupg/gpg2.exe' > gpg = 'c:/program files (x86)/gnu/gnupg/gpg2.exe' > > subprocess.Popen('gpg', shell=True) > > It fails to run gpg and is not expanding the variable.  Is there a way > to do this th

Re: [Tutor] Socket and Changing IP's

2011-02-28 Thread Sander Sweers
On Tue,  1 Mar 2011, 01:02:23 CET, Jacob Bender wrote: >          I'm trying to be a host without having to keep the computer on ALL > of the time. Acting as a "Dropbox" would be an example. My IP doesn't > change very often. It's stayed the same for days. The best solution here is to get a

Re: [Tutor] Problem with print

2010-12-19 Thread Sander Sweers
On 19 December 2010 21:54, jtl999 wrote: >  File "GettingStarted.py", line 91 >    print ("Lesson Two") >        ^ > SyntaxError: invalid syntax > > Python 2.6.5 You are using a howto for python version 3.X but you are using python 2.X. In python 3 the print statement was changed to a function.

Re: [Tutor] why "ifconfig" is alway running?

2010-12-19 Thread Sander Sweers
On 19 December 2010 13:43, lei yang wrote: > Right, it gets stuck at the readline(), is there a function not get > stuck to instead of readline(). readline() will keep reading stdout until it received a newline character. So if there is nothing to read it will wait forever. The solution is to wai

Re: [Tutor] Python vs. MATLAB

2010-12-07 Thread Sander Sweers
On 7 December 2010 00:16, Steven D'Aprano wrote: > Oh boy, is that a can of worms... and this is going to be a long post. You > might want to go make yourself a coffee first :) Great writeup and much appreciated :-). Thx Sander ___ Tutor maillist - T

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] 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] 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] 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] 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] 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 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] 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] 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] 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] 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] 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] 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] 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] 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 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] 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] 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] 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] 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] 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] 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] 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] 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] 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 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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

  1   2   3   >