[Tutor] While and for loops

2009-07-13 Thread Todd Matsumoto
Hello, The other day I was playing with a while loop with a for loop nested inside. Within the for loop I had a condition to break the loop, but when loop ran it never existed the loop. I went back and looked in Programming Python to read about loops and I've got two questions (related to each

Re: [Tutor] find and replace relative to an nearby search string

2009-07-13 Thread pedro
Hi and thanks everyone for the enlightenment. I guess pyparsing is the way to go then. I just installed it and am trying it out. It looks good for all the stuff I need to do in Nuke frequently. I am going to do a bit of testing with Paul's solution. Cheers Pete __

Re: [Tutor] browser encoding standards?

2009-07-13 Thread Serdar Tumgoren
> That's precisely the solution that worked for me, though I should say that I only tested this in Firefox 3 on Ubuntu 9.04. The below blog post circa 2006 suggests that IE at least uses some behind-the-scenes magic to decide on an encoding when the declaration doe not appear in the Content heade

Re: [Tutor] browser encoding standards?

2009-07-13 Thread Alan Gauld
"Serdar Tumgoren" wrote I guess you forgot to output a tag that defines the content-type of the page. Aha! Yes indeed. I was just writing out data quick and dirty for testing purposes and forgot to write out the headers. I added Content Header info and all works fine. OK, What kind of m

Re: [Tutor] browser encoding standards?

2009-07-13 Thread Alan Gauld
"Serdar Tumgoren" wrote The problem I stumbled into is that when I used UTF-8, several characters showed up as gobbledygook in my Firefox browser. Specifically, the characters "\u201c" and "\u201d" (quote marks) were not carrying over. Some googling revealed that I should change my browser's d

Re: [Tutor] gtk.Notebook error

2009-07-13 Thread Alan Gauld
"Amit Sethi" wrote I am having problem with adding pages to gtk.Notebook : I know nothing about Gtk so I could mbe missing something here but Now while creating I do : def new_tab(widget,widget_render): notebook.new_tab(widget_render) notebook = SmNotebook() These 2 line

[Tutor] gtk.Notebook error

2009-07-13 Thread Amit Sethi
Hi , I am having problem with adding pages to gtk.Notebook : What I want is to be able to pass a random container widget to a new tab: thus my code is : class SmNotebook(gtk.Notebook): def __init__(self): gtk.Notebook.__init__(self) #set the tab proper

Re: [Tutor] browser encoding standards?

2009-07-13 Thread Serdar Tumgoren
> I guess you forgot to output a tag that defines the content-type of > the page. Aha! Yes indeed. I was just writing out data quick and dirty for testing purposes and forgot to write out the headers. I added Content Header info and all works fine. Thanks! __

Re: [Tutor] browser encoding standards?

2009-07-13 Thread Stefan Behnel
Serdar Tumgoren wrote: > I just ran into a glitch that got me wondering about the proper > encoding to use when outputting data for non-technical folks. > > I took pains to ensure that I converted a number of XML feeds to UTF-8 > prior to storage in a database. And then, when pulling the feed data

[Tutor] browser encoding standards?

2009-07-13 Thread Serdar Tumgoren
Hi everyone, I just ran into a glitch that got me wondering about the proper encoding to use when outputting data for non-technical folks. I took pains to ensure that I converted a number of XML feeds to UTF-8 prior to storage in a database. And then, when pulling the feed data from a database to

Re: [Tutor] Saving class instances

2009-07-13 Thread Alan Gauld
"Thomas Scrace" wrote class with attributes like name, artist, year etc. However, I am at a loss as to how to save these instances so that they can be retrieved the next time I run the program. I assume I need to write them to a file somehow, That's one way and you can find an example

Re: [Tutor] Saving class instances

2009-07-13 Thread Thomas Scrace
I think I will give both approaches a go, since this is just a learning exercise anyway. Thanks very much for your help. Oh, and sorry for accidentally quoting the whole digest last time. Won't happen again! Tom On 13 Jul 2009, at 17:53, tutor-requ...@python.org wrote: I think you are b

Re: [Tutor] Pythonify this code!

2009-07-13 Thread ALAN GAULD
Steganography's really neat! You should look into it. > > I did a quick lookup on Wikipedia. > Basically what his code does is takes an image, and it twiddles the least significant bits > > Interestingly when I was at university the head of signal processing was into crypto stuff and was look

Re: [Tutor] Saving class instances

2009-07-13 Thread Daniel Woodhouse
I think you are better off using a database in this situation, sqlite3 is a good choice since no extra setup is required. See http://docs.python.org/library/sqlite3.html And to answer your question, the python pickle module can save class instances, see http://docs.python.org/library/pickle.html

[Tutor] Saving class instances

2009-07-13 Thread Thomas Scrace
ent was scrubbed... URL: <http://mail.python.org/pipermail/tutor/attachments/20090713/ad0174f6/attachment-0001.htm > -- Message: 2 Date: Mon, 13 Jul 2009 07:37:45 -0400 From: Kent Johnson To: Markus Hubig Cc: tutor@pyth

Re: [Tutor] for statement with addition ...

2009-07-13 Thread Markus Hubig
On Mon, Jul 13, 2009 at 2:08 PM, Dave Angel wrote: > Markus Hubig wrote: > >> Hi @all, >> >> within diveintopython I often found a for-statement like this: >> >> f for f in bla: >>print f >> >> So what actually is the first f for ... is it just to declare f before >> starting the for loop? I

Re: [Tutor] for statement with addition ...

2009-07-13 Thread Dave Angel
Markus Hubig wrote: Hi @all, within diveintopython I often found a for-statement like this: f for f in bla: print f So what actually is the first f for ... is it just to declare f before starting the for loop? I can't find any information on python.org and it's hard to google this kinda st

Re: [Tutor] thesaurus

2009-07-13 Thread Dave Angel
Pete Froslie wrote: The url function btw: def url(): fin = open("journey_test.txt", "r") response = re.split(r"[/|/,\n, , ,:\"\"\.?,)(\-\<>\[\]'\r']", fin.read()) thesaurus = API_URL + response[word_number] + '/' #API_URL is established at the start of the code return thesaurus

[Tutor] Xampp & Python

2009-07-13 Thread Rommel Asibal
Hello All, I am trying to go through the "Python Power!" book and i am at the part where i need to setup a web server. I am thinking of using XAMPP and have checked its site and wanted to try using mod_python. I am using Python 3.1 but from initial looks it seems mod_python doesnt support it, co

Re: [Tutor] for statement with addition ...

2009-07-13 Thread Kent Johnson
On Mon, Jul 13, 2009 at 6:50 AM, Markus Hubig wrote: > Hi @all, > > within diveintopython I often found a for-statement like this: > > f for f in bla: >     print f > > So what actually is the first f for ... is it just to declare f before > starting the for loop? I can't find any information on py

Re: [Tutor] for statement with addition ...

2009-07-13 Thread Rommel Asibal
Markus, That looks like a typo. remove it and it should work. On Mon, Jul 13, 2009 at 4:50 AM, Markus Hubig wrote: > Hi @all, > > within diveintopython I often found a for-statement like this: > > f for f in bla: > print f > > So what actually is the first f for ... is it just to declare f

Re: [Tutor] Pythonify this code!

2009-07-13 Thread Dave Angel
Muhammad Ali wrote: Hi, This is my first attempt at python. I tried my hand at steganography for fun. The code includes separate, combine, encode, decode functions. The separate function takes a number and it's base and returns a list containing each digit of the number in a list, vice versa for

[Tutor] for statement with addition ...

2009-07-13 Thread Markus Hubig
Hi @all, within diveintopython I often found a for-statement like this: f for f in bla: print f So what actually is the first f for ... is it just to declare f before starting the for loop? I can't find any information on python.org and it's hard to google this kinda stuff. - Markus -- --

Re: [Tutor] Pythonify this code!

2009-07-13 Thread Luke Paireepinart
> > > > I tried my hand at steganography >> > > Never heard of it before![snip] > > I didn't notice anything that would be v3 specific. Also I can't > comment on the algorithm since I don't really know what its > doing! > Alan, Steganography's really neat! You should look into it. Basically wha

Re: [Tutor] Pythonify this code!

2009-07-13 Thread Alan Gauld
"Muhammad Ali" wrote I tried my hand at steganography Never heard of it before! #The code starts here: def separate(num, base): li = [] while num / base > 0: li.insert(0, num % base) num = num / base li.insert(0,num) return li def combine(tup, base): num = 0

Re: [Tutor] find and replace relative to an nearby search string in afile

2009-07-13 Thread Alan Gauld
"Pete O'Connell" wrote I am always looking for the line " name Write1" as my starting point. In the first example below, I want to replace the path, which is 2 lines above it. I have made a basic script to do that and it works fine. The problem I am having is when the number of lines between

Re: [Tutor] find and replace relative to an nearby search string

2009-07-13 Thread Paul McGuire
This is a good little pyparsing exercise. Pyparsing makes it easy to define the structure of a "Write { ( )* }" block, and use the names given to the parsed tokens to easily find the "name" and "file" entries. from pyparsing import (Literal, Word, alphanums, empty, restOfLine, dictOf) # make up

[Tutor] Pythonify this code!

2009-07-13 Thread Muhammad Ali
Hi, This is my first attempt at python. I tried my hand at steganography for fun. The code includes separate, combine, encode, decode functions. The separate function takes a number and it's base and returns a list containing each digit of the number in a list, vice versa for combine. The encode f

Re: [Tutor] Why is there no uninstall option for setup.py?

2009-07-13 Thread A.T.Hofkamp
Hai, Welcome to the complexities of package management :) wcyee wrote: Hi, When I am able to find and install a windows package distributed as an exe file, I can just go to "Add & Remove Programs" in the "Control Panel" and uninstall it. That's what I call an OS package manager. My Linux on

Re: [Tutor] find and replace relative to an nearby search string in a file

2009-07-13 Thread A.T.Hofkamp
Pete O'Connell wrote: Write { file /Volumes/raid0/Z353_002_comp_v27.%04d.cin file_type cin name Write1 xpos 13762 ypos -364 } The simplest approach imho is to parse the input with a proper parser, eg PLY or pyparsing. If you want to do the parsing manually, I'd start by classifying eac