Re: [Tutor] glob.glob(pattern, dir) ?

2009-06-09 Thread Sander Sweers
2009/6/9 spir : > is there a way to make glob work in a specified dir? glob needs a pathname and uses the current dir if no full path is given. Prepend the path to your match (*.txt in example below) and it works like you want it. >>> import glob >>> glob.glob('c:\\GTK\\*.txt') ['c:\\GTK\\license

Re: [Tutor] glob.glob(pattern, dir) ?

2009-06-09 Thread Sander Sweers
On Tue, 2009-06-09 at 20:23 +0200, spir wrote: > Le Tue, 9 Jun 2009 17:40:26 +0200, > Sander Sweers s'exprima ainsi: > > 2009/6/9 spir : > > > is there a way to make glob work in a specified dir? > > > > >>> import glob > > >>> gl

Re: [Tutor] gui

2009-06-09 Thread Sander Sweers
Can you try this again but please use plain text instead of html.. If you can not send in plain text then use a pastebin like python.pastebin.com to show your code and/or error messages. Greets Sander On Tue, 2009-06-09 at 17:41 -0400, Essah Mitges wrote: > I was wondering in a python made in py

Re: [Tutor] recursive glob -- recursive dir walk

2009-06-10 Thread Sander Sweers
2009/6/10 spir : > A foolow-up ;-) from previous question about glob.glob(). Hopefully no misunderstanding this time :-) > I need to 'glob' files recursively from a top dir (parameter). Tried to use > os.walk, but the structure of its return value is really unhandy for such a > use (strange, be

Re: [Tutor] character counter

2009-06-29 Thread Sander Sweers
2009/6/27 julie : > file = open("/Users/meitalamitai/Documents/Computer > Science/Python/Homework/Lorem_Ipsum.py") > lines = 0 > for line in file: >     lines=lines+1 > print '%r has %r lines' % ("Lorem_Ipsum.py", lines) >    if char >= 1000: >     break You can do something like below (untest

Re: [Tutor] Python Programming exercise

2009-07-01 Thread Sander Sweers
2009/7/1 Daniel Sato : > I have been going through some Python Programming exercises while following > the MIT OpenCourseWare Intro to CS syllabus and am having some trouble with > the first "If" exercise listed on this page: > > http://en.wikibooks.org/wiki/Python_Programming/Conditional_Statement

Re: [Tutor] Popen problem with a pipe sign "|"

2009-07-03 Thread Sander Sweers
2009/7/3 hyou : > Do you know how can I run the command with | sign correctly with popen? Or > if that’s not possible, can you give me a way to control the output from > subprocess.call? subprocess.call does not support this but subprocess.Popen does. See Doug Hellmann's PMOTW which explains how t

Re: [Tutor] Popen problem with a pipe sign "|"

2009-07-03 Thread Sander Sweers
2009/7/3 hyou : > Hi Sander, > > Thanks for the reply. However, the reason that I have to use subprocess.call > is that if I use > subprocess.Popen, the pipe sign "|" will break the execution of the command > (though I don't know > why). Do you know how can I put "|" correctly in Popen then? (The

Re: [Tutor] Popen problem with a pipe sign "|"

2009-07-04 Thread Sander Sweers
Again, You need to also post to the list!! On Fri, 2009-07-03 at 22:32 -0400, Shawn Gong wrote: > I see what you mean. However in my case the | sign simply constitute an > argument. I'm actually calling devenv.com, which is the MS VS2005's building > command. The whole command looks like: > "...

Re: [Tutor] Popen problem with a pipe sign "|"

2009-07-06 Thread Sander Sweers
2009/7/6 hyou : > Do I post to the list by also replying to Python Tutor List? Yes, thanks. > Thanks for the answer! I found the problem was because I put the 2nd > argument to Popen with Shell = true. Though I'm not sure why it doesn't work > with Shell = true while the same setting works for ot

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread Sander Sweers
2009/7/7 John [H2O] : > > The data is just x,y data where x = datetime objects from the datetime > module. y are just floats. It is bundled in a numpy array. I might be totally off but, did know that you can compare datetime objects? >>> from datetime import datetime >>> d1 = datetime.now() >>> d

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread Sander Sweers
2009/7/7 David Kim : > opener = urllib2.build_opener(MyHTTPRedirectHandler, cookieprocessor) > urllib2.install_opener(opener) > > response = > urllib2.urlopen("http://www.dtcc.com/products/derivserv/data_table_i.php?id=table1";) > print response.read() > > > I suspect I am not understanding s

Re: [Tutor] sftp get single file

2009-07-17 Thread Sander Sweers
2009/7/17 Matt Herzog : > Hello All. > > I need to use paramiko to sftp get a single file from a remote server. > The remote file's base name will be today's date (%Y%m%d) dot tab. > I need help joining the today with the .tab extension. Do I need globbing? > > example: 20090716.tab > > #!/usr/bin/

Re: [Tutor] != -1: versus == 1

2009-07-17 Thread Sander Sweers
2009/7/17 pedro : > > for line in theLines: >   if line.find("Source Height") != -1: > #etc... > ### > > Is there some special reason for this. Why not just write "If it is equal to > one" Yes, str.find() returns -1 on failure. See b

Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Sander Sweers
2009/7/17 Michiel Overtoom : > This is actually the first time I see that BeautifulSoup is NOT able to > parse a webpage... Depends on which version is used. If 3.1 then it is much worse with malformed html than prior releases. See [1] for more info. Greets Sander [1] http://www.crummy.com/softw

Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Sander Sweers
2009/7/17 Che M : > table = soup.find("td",id="dataTable tm10") Almost right. attrs should normall be a dict so {'class':'dataTable tm10'} but you can use a shortcut, read on. > > > When I look at the page source for that page, there is this section, which > contains the

Re: [Tutor] weather scraping with Beautiful Soup

2009-07-18 Thread Sander Sweers
2009/7/18 Che M : > table = soup.find("table","dataTable tm10")  #find the table > tbody = table.find("tbody")  #find the table's body You can do this in one step. tbody = soup.find('tbody') Greets Sander ___ Tutor maillist - Tutor@py

Re: [Tutor] sftp get single file

2009-07-20 Thread Sander Sweers
I do not know paramiko but looking over the client documentations... 2009/7/20 Matt Herzog : > if __name__ == "__main__": >t = paramiko.Transport((hostname, port)) >t.connect(username=username, password=password) >sftp = paramiko.SFTPClient.from_transport(t) Up to here it looks fine.

Re: [Tutor] sftp get single file

2009-07-20 Thread Sander Sweers
2009/7/20 Matt Herzog : > Traceback (most recent call last): >  File "./scpgetter.py", line 20, in ? >      sftp.get(remotepath, localpath) >        File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 584, > in get >          File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py

Re: [Tutor] sftp get single file

2009-07-20 Thread Sander Sweers
2009/7/20 Matt Herzog : > The file is there. I can sftp it using fugu. I am sure it is but paramiko can't find it. > The path is /20090720.tab since the file lives in a jail. Issue a sftp.listdir() and see what paramiko sees on the remote server. Greets Sander __

Re: [Tutor] sftp get single file

2009-07-20 Thread Sander Sweers
2009/7/20 Matt Herzog : > remotepath = 'datestr' Ok, you are now making a string. > remotepath = datestr Like Kent wrote the datestr can include other characters. So I would try "/%Y%m%d.tab". > sftp.get(remotepath, localpath) >  File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line

Re: [Tutor] sftp get single file

2009-07-20 Thread Sander Sweers
Please reply to the list. 2009/7/20 Matt Herzog : > Yeah. I have no idea if I am able to do this. The jail makes it ambiguous. There is no difference, the jail just moves the root directory as seen by the client. Did you do as suggested earlier to use listdir()? This will tell you how paramiko s

Re: [Tutor] Bouncing mail

2009-07-22 Thread Sander Sweers
2009/7/22 Dave Angel : > Anyone else seeing these? Unfortunately yes. Very annoying... :( Greets Sander ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] subprocess.call

2009-07-27 Thread Sander Sweers
On Mon, 2009-07-27 at 14:40 -0400, davidwil...@safe-mail.net wrote: > OK I think I found my error, here is what I did: > > flags = set([file for file in glob.glob('flag-*.svg')]) > > def call(cmd): > subprocess.call([cmd], shell=True) You hardly ever need shell=True. And using [cmd] is close

Re: [Tutor] Problems understanding control flow

2009-07-30 Thread Sander Sweers
2009/7/30 Eduardo Vieira : With == you are testing if the 2 values are exactly the same. So 'one' == 'one' will return True but 'one; == 'one two' will return False. With in you test if the value is part of a another value. So using the same value as above 'one' in 'one' will return True but 'one

Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread Sander Sweers
2009/8/6 Dave Angel : > > You have to choose your poison. I prefer no poison. This is exactly what inotiy was made for and although I never used it there is a python module for it [1]. It would be great if you can post your experience with it. Greets Sander [1] http://trac.dbzteam.org/pyinotify/

Re: [Tutor] Easy Problem

2009-09-01 Thread Sander Sweers
2009/9/1 Luke Paireepinart : txt = "Hi          how are you?" " ".join(txt.strip().split()) > 'Hi how are you?' txt.strip() only remove leading and trailing white space so does nothing in your example. However it works because txt.split() removes the excessive white space between the tex

Re: [Tutor] Rounding to n significant digits

2009-09-02 Thread Sander Sweers
2009/9/2 Alan Gauld : > That having been said the two approaches, string or math, are equally > valid. I suspect the math version will be much slower since it calls > several functions but I haven't timed  it. > >>> def round_to_n(x, n): >>>         fmt = "%%.%de" % (n) >>>         return float( fm

Re: [Tutor] Fwd: Executing a command from a specific directory

2009-09-16 Thread Sander Sweers
On Wed, 2009-09-16 at 18:03 +0530, Ansuman Dash wrote: > if "Request timed out.." not in a: > print("Ping is not successful.") > pLogger.info("Ping is not successful.") This will check for the string "Request timed out.." is NOT in a. Now when the ping i

Re: [Tutor] Executing a command from a specific directory

2009-09-18 Thread Sander Sweers
On Fri, 2009-09-18 at 14:46 +0530, Ansuman Dash wrote: > I have written it like that. It is like press 1 and it ll download > file1 and > press 2 it ll download file2 etc But without providing people how you accomplish this there is no way to help. > But my question was I am using "time.sleep

Re: [Tutor] order data

2009-09-18 Thread Sander Sweers
2009/9/18 Rayon : I will assume array == python list. > I have a array with this data in it How are you reading the data? Do you convert all the numbers to floats? If so you will need to think about precision of the floats. If you want to preserve the precision look into the decimal module. > 0

Re: [Tutor] Determine Filetype

2009-09-19 Thread Sander Sweers
On Fri, 2009-09-18 at 16:48 -0400, Kent Johnson wrote: > > So, the __init__.py file of the GAE evinronment's ctypes library is > > broken, as it's importing from a package that doesn't exist. Right? > > Probably ctypes is not supported in GAE, that would be a pretty big > security hole. There is

Re: [Tutor] Determine Filetype

2009-09-19 Thread Sander Sweers
On Sat, 2009-09-19 at 17:20 +0200, ad...@gg-lab.net wrote: > I want to check the extension of an uploaded file. So i've created a > list with allowed extensions: > > enabled_ext = ['gif', 'jpeg', 'png', 'bmp', 'tiff'] If this does not change make it s tuple. It does not change what is written bel

Re: [Tutor] Determine Filetype

2009-09-19 Thread Sander Sweers
On Sat, 2009-09-19 at 17:36 +0200, ad...@gg-lab.net wrote: > if OBJECT in LIST: > > Well, but i'd like to read the page of the python tutorial regarding > this. I'm not able to locate it. Can you help me? When in the python interpreter type help('in') and you should have all info you need about t

[Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
Hello Tutors, Because a website was giving me issues with unicode character I created a function to force the encoding. I am not sure it is the correct way to handle these things. def reader(fobject, encoding='UTF-8'): '''Read a fileobject with specified encoding, defaults UTF-8.''' r = co

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote: > > def reader(fobject, encoding='UTF-8'): > >'''Read a fileobject with specified encoding, defaults UTF-8.''' > >r = codecs.getreader(encoding) > >data = r(fobject) > >return data > > > > I would call it like reader(urllib2.url

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Sander Sweers
2009/9/24 ALAN GAULD : >> print message[::-1] > > Yes, the for loop doing one character at a time will be much > slower than using a slice. The slice is more pythonic but less general. > A reverse loop is something that is often needed in programming > solutions so it's useful to know how to do it

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Sander Sweers
On Thu, 2009-09-24 at 08:07 -0400, Serdar Tumgoren wrote: > You should find plenty by googling for "python slice step sequence" Now that I know what to look for I went to the online python docs [1] and tried to find where it has been documented. Unfortunately all the slicing examples I found do

Re: [Tutor] New to python: some advises for image processing tool

2009-10-02 Thread Sander Sweers
2009/10/2 Stefan Behnel : > Without looking further into your problem, there are two (main) general > purpose image manipulation libraries for Python (that I know of) that you > may want to look at: PIL and ImageMagick. At least ImageMagick supports FITS. There is a python module for fits files. N

[Tutor] if n == 0 vs if not n

2009-10-05 Thread Sander Sweers
Hi Tutors, I am going through someone's python script and I am seeing a lot of the following boolean checks. if not s == "" if not n == 0 if b == True if not b == True etc.. All of these can be written without the == notation like "if n", "if s" etc. Now in this case where it is only used

Re: [Tutor] if n == 0 vs if not n

2009-10-05 Thread Sander Sweers
Thanks Wesly/Vern for the replies. On Mon, 2009-10-05 at 21:56 +0200, Luke Paireepinart wrote: > if not n == 0 > > if b == True can be written as if b. > > > However, > if not n == 0 can be written as if n != 0 but NOT as if n. > The reason why is that 0 is not equivalent to False even

Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Sander Sweers
Thanks all for the informative discussion. To re-confirm it was mostly for boolean checks like "if b == True". Greets Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/t

Re: [Tutor] if n == 0 vs if not n

2009-10-08 Thread Sander Sweers
On Thu, 2009-10-08 at 12:58 -0700, wesley chun wrote: > wow, as the OP, you must have been surprised to see how far we have > taken your (seemingly) simple question. Pleasently suprised :-) And I am gratefull to see the heavy weights join in. > however, what i did *not* mention is that these (abb

Re: [Tutor] "if clause" in list comprehensions.

2009-10-19 Thread Sander Sweers
2009/10/19 Eduardo Vieira : > mylist = ['John', 'Canada', 25, 32, 'right'] > a = [item.upper() for item in mylist if type(item) == type('good')] Usually it is recommended to use hasattr() instead of type() hasattr(s, 'upper') > returned this: ['JOHN', 'CANADA', 'RIGHT'] > I was expecting this

Re: [Tutor] "if clause" in list comprehensions.

2009-10-19 Thread Sander Sweers
2009/10/19 Alan Gauld : >> Usually it is recommended to use hasattr() instead of type() >>   hasattr(s, 'upper') > > Nope, they do  completely different things > I think you might be thinking of isinstance() which can be used instead of > type(). I see you use hasattr as a means of testing for a me

Re: [Tutor] optional sys.argv parsing

2009-10-29 Thread Sander Sweers
On Thu, 2009-10-29 at 17:30 -0400, Andre Walker-Loud wrote: > I have a simple question. I am writing a little program that will > make some plots of data files. I want to have optional args to pass, > for example to specify the plot ranges. I have never written a script/ > code that takes o

Re: [Tutor] module name completion suggestions drop down?

2009-11-11 Thread Sander Sweers
On Wed, 2009-11-11 at 13:11 -0800, Kristin Wilcox wrote: > I was wondering about something I've seen in people's video tutorials > -- these people are using IDLE like I am, but they get these drop down > suggestions for module names that I'm not experiencing. This is done by holding ctrl and press

Re: [Tutor] Unexpected iterator

2009-11-12 Thread Sander Sweers
2009/11/12 Jeff R. Allen : > Then I tried this to (maybe) set both a and b to 0: > a, b = 0 > Traceback (most recent call last): >  File "", line 1, in > TypeError: 'int' object is not iterable I think you are looking for. >>> a = b = c = 300 Greets Sander _

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Sander Sweers
2009/11/16 Dave Angel : > Alternatively, you could subclass it, and write your own.  At a minimum, the > __exit__() method should close() the stream. This triggered my to dig into this a bit. This is not fixed untill python 3.1 but seems easilly added to the ZipFile class. My attempt to backport t

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Sander Sweers
2009/11/16 Kent Johnson : > You might want to report this as a bug against 2.6 and submit this > change as a proposed fix. It's easy to do, see I poked around in the bug tracker and found [1]. It will be in 2.7 and was *not* accepted for 2.6. If anyone wants to add this in themselves see [2]. Gr

Re: [Tutor] socket timeout

2009-11-27 Thread Sander Sweers
2009/11/27 Stefan Lesicnik : > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > #s.setdefaulttimeout(1) > s.connect((proxy,port)) I have never used socket but a quick look at the docs [1] my guess is that you should use use s.settimeout() [2]. The docs say that setdefaulttimeout [3] wi

Re: [Tutor] Equivalent exception of os.path.exists()

2009-11-30 Thread Sander Sweers
2009/11/30 biboy mendz : > clause, it should be on the fobj-open line. But im still looking for the > exception that will be raised when i input a filename and that file already > exists. I hope you get what i mean :-) There is no exception to alert you a file already exists. Depending on how you

Re: [Tutor] File renaming using os.rename problem (spir)

2009-12-08 Thread Sander Sweers
On Tue, 2009-12-08 at 14:55 -0800, Roy Hinkelman wrote: > shutil.copy2(_files_to_mod + "\\" + fname, _files_to_mod + "\\" + > new_name) You can make os.path.join sort out the directory seprator for you. It will add a / under linux and \ under windows. >>> os.path.join('Testing dir','oldname dir',

Re: [Tutor] Using split with a backslash

2008-04-02 Thread Sander Sweers
On Wed, Apr 2, 2008 at 7:44 AM, Bryan Fodness <[EMAIL PROTECTED]> wrote: > I have a data pair separated by a backslash. I didn' t think it would see > an end of line if the backslash was inside the quotes. The backlash is seen as an escape character. Try the below, notice the string prefix r and

Re: [Tutor] Newb Learning Question

2008-04-03 Thread Sander Sweers
Should be replying to the listSorry :( On Thu, Apr 3, 2008 at 11:14 AM, Sander Sweers <[EMAIL PROTECTED]> wrote: > On Thu, Apr 3, 2008 at 8:21 AM, Jeffrey Dates <[EMAIL PROTECTED]> wrote: > > > > 3rd alternative: if c > 'm': print c > > &

Re: [Tutor] datetime module problem

2008-04-18 Thread Sander Sweers
On Fri, Apr 18, 2008 at 4:49 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > Got it, I think. Here is a my somewhat simplified version of your daysDelta script. It uses less variables but I am not sure if it is faster? http://py77.python.pastebin.com/m14e40

Re: [Tutor] string from input file

2008-04-29 Thread Sander Sweers
On Tue, Apr 29, 2008 at 11:54 PM, Bryan Fodness <[EMAIL PROTECTED]> wrote: > I am trying to get values from an input file, > > 0.192 > Custom > 15 > IN > > but, when I check to see if they are equal it is not true. > > f = open(infile, 'r') > s = f.readlines() > f

Re: [Tutor] Local Unbound Mystery

2008-09-19 Thread Sander Sweers
On Fri, Sep 19, 2008 at 21:51, Wayne Watson <[EMAIL PROTECTED]> wrote: The code does not belong the Traceback. When I run the code I get a different issue, see below. > def sync_high2low_files(): > morris() > sync_low2high_files() Search for the difference. Greets Sander _

Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Sander Sweers
On Sat, Sep 20, 2008 at 00:23, Wayne Watson <[EMAIL PROTECTED]> wrote: > Well, it made a difference, and now program and output are in agreement. Not really the code has an error so it could not have worked. > updown = +1 > while keyop <> 0: You forgot to create keyop in this example. > Unbound

Re: [Tutor] bug in exam score conversion program

2008-10-04 Thread Sander Sweers
On Sat, Oct 4, 2008 at 12:11, David <[EMAIL PROTECTED]> wrote: > I am quite happy with my code, but there is a bug: if the score is 100, then > the program calculates 100/10 = 10. However, the tuple runs to 9, leaving me > with an error message: IndexError: tuple index out of range > > I can't figu

[Tutor] Multiple lists from single list with nested lists

2008-10-20 Thread Sander Sweers
Hi, I am learning myself python and I need to create 2, or more but let's use 2 as an example, lists from a list with nested lists. For example the below, ['Test1', 'Text2', ['1', '2'], 'Text3'] Should result in, [['Test1', 'Text2', '1', 'Text3'], ['Test1', 'Text2', '2', 'Text3'] I though of u

Re: [Tutor] Multiple lists from single list with nested lists

2008-10-21 Thread Sander Sweers
On Tue, Oct 21, 2008 at 01:36, Kent Johnson <[EMAIL PROTECTED]> wrote: >> somelist = ['Test1', 'Text2', ['1', '2'], 'Text3'] >> templist = [] >> for x in range(len(somelist[2])): >>templist.append([somelist[0], somelist[1], somelist[2][x], somelist[3]]) > > Is it always just the third item that

[Tutor] Manipulate list in place or append to a new list

2008-11-01 Thread Sander Sweers
Hi, What is the better way to process data in a list? Make the changes in place, for example somelist = [1,2,3,4] for x in range(len(somelist)): somelist[x] = somelist[x] + 1 Or would making a new list like somelist = [1,2,3,4] newlist = [] for x in somelist: newlist.append(x + 1) Or

Re: [Tutor] Manipulate list in place or append to a new list

2008-11-02 Thread Sander Sweers
On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote: > Use a list comprehension: > somelist = [ x+1 for x in somelist ] Got it. > Note that this creates a new list, replacing the one that was in > somelist. If you need to actually modify somelist in place (rare) then > use someli

Re: [Tutor] Manipulate list in place or append to a new list

2008-11-02 Thread Sander Sweers
On Sun, Nov 2, 2008 at 01:23, bob gailer <[EMAIL PROTECTED]> wrote: >> What is the better way to process data in a list? > > Depends on what you mean by "better". Could mean faster, smaller, more > readable, or ?? Get clear on your goals. Inexperienced beginner programmer asking more experienced p

[Tutor] File IO flush

2008-12-08 Thread Sander Sweers
Hello All, I was playing around with the zipfile module and wrote a simple script to unzip a zip file. I then looked around on the internet and found the recipe 252508 [1] on the active state cookbook website. In this recipe the author calls flush() and then close() on a file object being written

Re: [Tutor] reading inputs from keyboard

2008-12-14 Thread Sander Sweers
On Sun, Dec 14, 2008 at 18:21, Robert Berman wrote: > RTFM. Thank you for your non contribution python tutor mailing list.The minimum you could do is point to the FM which others luckily already did. Greets Sander ___ Tutor maillist - Tutor@python.or

[Tutor] telnetlib unable to cath gaierror

2008-12-28 Thread Sander Sweers
Hello All, I am having issues cathing exceptions from telnetlib. What I am doing is: - tc = telnetlib.Telnet() try: tc.open('abc') except gaierror: print 'Invalid hostname' - Which gives me "NameError: name 'gaierror' is not define

Re: [Tutor] telnetlib unable to cath gaierror

2008-12-28 Thread Sander Sweers
On Sun, Dec 28, 2008 at 19:17, Steve Willoughby wrote: > On Sun, Dec 28, 2008 at 07:09:51PM +0100, Sander Sweers wrote: >> I am having issues cathing exceptions from telnetlib. What I am doing is: >> except gaierror: >> Which gives me "NameError: name 'gaierror'

Re: [Tutor] Top posters to tutor list for 2008

2009-01-02 Thread Sander Sweers
On Fri, Jan 2, 2009 at 13:52, Kent Johnson wrote: > Or ask more questions, that works too! So you and Alan ask the most questions ;-) Seriously now, this really shows the power of Python and I'll have a good time figuring out how this exactly works. Thanks to all the Tutors for year of great su

[Tutor] Kent's top poster script operator.itemgetter()

2009-01-02 Thread Sander Sweers
Hello All, While trying to inderstand Kent's script [1] I struggle on the use of operator.itemgetter(1) from the following piece of code. I understand it makes it sort on the second value of the counts.iteritems but I do not understand how operator.itemgetter(1) works. for name, count in sorted(

Re: [Tutor] Kent's top poster script operator.itemgetter()

2009-01-03 Thread Sander Sweers
On Sat, Jan 3, 2009 at 05:15, Kent Johnson wrote: > On Fri, Jan 2, 2009 at 6:12 PM, Sander Sweers wrote: >> not understand how operator.itemgetter(1) works. > > See > http://personalpages.tds.net/~kent37/kk/7.html#e7the-operator-module Ok, if I understand this correctl

Re: [Tutor] repply

2009-01-04 Thread Sander Sweers
On Sun, Jan 4, 2009 at 14:18, prasad rao wrote: z=[] for x in range(1000): > if divmod(x,3)[1]==0:z.append(x) > if divmod(x,5)[1]==0:z.append(x) sum(set(z)) > 233168 This can be done in one line of python. >>> sum([x for x in range(1000) if x %3 == 0 or x % 5 == 0]) 233168 Greets

Re: [Tutor] Usage of for loop

2009-01-05 Thread Sander Sweers
On Mon, Jan 5, 2009 at 14:19, vanam wrote: > I am trying tounderstand the below lines of code but of no avail. Python can loop over many types of sequences.. This can be a list, tuple or string and in your example a list. > a = ["cat", "window","defenestrate"] > for x in a: > print x, len(x

[Tutor] Convert values in a list back and forth from ints and time

2009-01-05 Thread Sander Sweers
Hello Tutors, I use the csv module to read and write a csv file. When I read the file into a new list I convert the ints and the dates to int and time objects so I can do calculations. I use the below function which works. def convertValue(value, dateformat, reverse=False): if reverse:

Re: [Tutor] Convert values in a list back and forth from ints and time

2009-01-06 Thread Sander Sweers
On Tue, Jan 6, 2009 at 04:38, bob gailer wrote: > I also suggest splitting convertValue into two functions, one that takes > strings and one that takes numbers. A lot easier to read and maintain. > > FWIW you could dispense with reverse in convertValue by testing the type of > value for int or str

Re: [Tutor] Convert values in a list back and forth from ints and time

2009-01-06 Thread Sander Sweers
On Tue, Jan 6, 2009 at 09:46, Alan Gauld wrote: > If you always convert the values back to strings then you could > just hold onto the original strings by storing them in a (str, val) tuple. > If you do calculations and modify anmy of them then convert the > value/string there and then and modify

Re: [Tutor] Interactive programming.

2009-01-06 Thread Sander Sweers
On Tue, Jan 6, 2009 at 20:12, WM. wrote: i = 5 j = 7 if i <= j: >print 'nudge, nudge' > else: > > File "", line 3 >else: > ^ > IndentationError: unexpected indent Python uses indentation to seperate code blocks and will throw an error if it finds inconsistan

Re: [Tutor] Opsware Global Shell Scripting

2009-01-07 Thread Sander Sweers
On Wed, Jan 7, 2009 at 22:04, Kayvan Sarikhani wrote: > #!/usr/bin/python > import os, sys > sys.stdout = open('timecheck.txt','w') > for servername in os.listdir('/opsw/Server/@'): > print '---', servername > os.system('rosh -n $SERVER_NAME -l $LOGNAME') > os.system('date') > sys.stdo

Re: [Tutor] Interactive programming.

2009-01-07 Thread Sander Sweers
On Wed, Jan 7, 2009 at 22:45, WM. wrote: > Norman Khine wrote: >> >> >>> i = 5 >> >>> j = 7 >> >>> if i <= j: >> ... print 'nudge', 'nudge' >> ... else: >> ... print 'whatever' >> ... >> nudge nudge > > The above is just what the tutorials said would happen. > Can anyone give me a step-

Re: [Tutor] Translating FORTRAN (77?) to Python?

2009-01-16 Thread Sander Sweers
On Fri, Jan 16, 2009 at 20:02, Wayne Watson wrote: > That is interesting. I'll pursue it. Thanks. Of course, at the moment, I > have no F77 compiler, so I can't even execute or use the code. Is there a > freebie F77 compiler out there? GCC supportd it http://gcc.gnu.org/. Greets Sander _

Re: [Tutor] Translating FORTRAN (77?) to Python?

2009-01-16 Thread Sander Sweers
On Fri, Jan 16, 2009 at 21:06, Wayne Watson wrote: > Anything under Win? Yes, minigw http://www.mingw.org/. Greets Sander ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Translating FORTRAN (77?) to Python?

2009-01-16 Thread Sander Sweers
On Fri, Jan 16, 2009 at 22:20, Wayne Watson wrote: > Will that do me any good if I implement my application under Win Python? Your question was for a fotran compiler to compile the source code. The fotran program is your reference point to compare the results to. Greets Sander __

[Tutor] datetime year problem, default year available?

2009-01-26 Thread Sander Sweers
Hello Tutors, I have some questions on setting the year in a datetime object via strptime. The issues is that in my date string I only have a day and a month ('11/27' for example). Now when I use datetime.strptime('11/27', ''%m/%d) I get a datetime object but the year is 1900. This makes sense as

Re: [Tutor] set key to sort

2009-01-31 Thread Sander Sweers
On Sat, Jan 31, 2009 at 10:51, prasad rao wrote: > I got a problem sorting a list of lists. > ml= > [[112, 'p'], [114, 'r'], [97, 'a'], [115, 's'], [97, 'a'], [100, 'd'], [97, > 'a'], [114, 'r'], [97, 'a'], [111, 'o']] > sorted(ml,key=?) > How can I formulate a key to sort based on the first eleme

Re: [Tutor] datetime year problem, default year available?

2009-01-31 Thread Sander Sweers
On Tue, Jan 27, 2009 at 01:01, Sander Sweers wrote: > month ('11/27' for example). Now when I use datetime.strptime('11/27', > ''%m/%d) I get a datetime object but the year is 1900. This makes > sense as I did not provide one. > > Then I saw that a da

Re: [Tutor] Precision with Decimal

2009-02-01 Thread Sander Sweers
On Sun, Feb 1, 2009 at 04:05, wrote: > "The decimal module incorporates a notion of significant places so that 1.30 > + 1.20 is 2.50. The trailing zero is kept to indicate significance. This is > the customary presentation for monetary applications." > > But I get: from decimal import Decima

Re: [Tutor] Simple PassGen

2009-02-09 Thread Sander Sweers
On Mon, Feb 9, 2009 at 23:32, Marc Tompkins wrote: > Don't forget - the "print" statement is going away in 3.0, and you really > should get into the habit of using the print() function instead for new > code. Why? Python's print statement is not going away in the 2.x series which will be supporte

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

<    1   2   3   >