Re: [Tutor] printing tree structure
karma wrote: Hi all , I have a nested list in the structure [root,[leftSubtree],[RightSubtree]] that I want to print out. I was thinking that a recursive solution would work here, but so far I can't quite get it working. This is what I have so far: Can someone suggest whether this is suited to a recursive solution and if so, what am I doing wrong. Thanks L = ['a', ['b', ['d', [], []], ['e', [], []]], ['c', ['f', [], []], []]] def printTree(L): for i in L: if isinstance(i,str): print 'Root: ', i else: print '--Subtree: ', i printTree(i) printTree(L) Root: a --Subtree: ['b', ['d', [], []], ['e', [], []]] Root: b --Subtree: ['d', [], []] Root: d --Subtree: [] --Subtree: [] --Subtree: ['e', [], []] # this shouldn't be here Root: e --Subtree: [] --Subtree: [] --Subtree: ['c', ['f', [], []], []] Root: c --Subtree: ['f', [], []] Root: f --Subtree: [] --Subtree: [] --Subtree: [] Using tabs in Python source code is never a good idea, and mixing tabs and spaces is likely to cause real problems, sometimes hard to debug. That's not the problem here, but I wanted to mention it anyway. The problem you have is the hierarchy doesn't show in the printout. There are a few ways to indicate it, but the simplest is indentation, the same as for Python source code. Once things are indented, you'll see that the line you commented as this shouldn't be here is correct after all. Add an additional parameter to the function to indicate level of indenting. Simplest way is to simply pass a string that's either 0 spaces, 4 spaces, etc. L = ['a', ['b', ['d', [], []], ['e', [], []]], ['c', ['f', [], []], []]] def printTree(L, indent=): for i in L: if isinstance(i,str): print indent, 'Root: ', i else: print indent, '--Subtree: ', i printTree(i, indent+) printTree(L) Root: a --Subtree: ['b', ['d', [], []], ['e', [], []]] Root: b --Subtree: ['d', [], []] Root: d --Subtree: [] --Subtree: [] --Subtree: ['e', [], []] Root: e --Subtree: [] --Subtree: [] --Subtree: ['c', ['f', [], []], []] Root: c --Subtree: ['f', [], []] Root: f --Subtree: [] --Subtree: [] --Subtree: [] Now I don't know if that's what your list of lists was supposed to mean, but at least it shows the structure of your printTree() loop. DaveA ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing a list to a window
On Tue, Jun 16, 2009 at 4:27 PM, Essah Mitges e_mit...@hotmail.com wrote: What I am trying to do is print a high score text file to a pygame window it kinda works...I don't know how to go about doing this... Do you know how to print text to a window? to read a file, just in a terminal window: f = open('somefile.txt', 'r') for line in f.readlines(): print line Just translate that. HTH, Wayne ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing a list to a window
Essah Mitges e_mit...@hotmail.com wrote What I am trying to do is print a high score text file to a pygame window it kinda works... How do you define kinda? It doesn't look like it works to me. The function main defined as def main(): high_file = open_file(high_score.txt, r) score = next_block(high_file) global score high_file.close() score is a local variable and has a value assigned Then you use gloobal which will have no affect so far as I can tell. Finally this function is being replaced by the second function main you defined. You might like to try getting it to work by printing on a console first! Then worry about the GUI bits. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing Problem python 3
Trying to print something with a { in it. Probably extremely simple, but it's frustrating me. :( print ('The \This is a test \ {') i get this error ValueError: Single '{' encountered in format string ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing Problem python 3
On Wed, Apr 29, 2009 at 2:42 PM, Dave Crouse dc...@crouse.us wrote: Trying to print something with a { in it. Probably extremely simple, but it's frustrating me. :( print ('The \This is a test \ {') i get this error ValueError: Single '{' encountered in format string It works for me: Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. print ('The \This is a test \ {') The This is a test { I guess you have redefined print() to use the latest style of string formatting: http://www.python.org/dev/peps/pep-3101/ Try using double braces {{ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing Problem python 3
On 30-Apr-09, at 12:12 AM, Dave Crouse wrote: Trying to print something with a { in it. Probably extremely simple, but it's frustrating me. :( print ('The \This is a test \ {') i get this error ValueError: Single '{' encountered in format string Worked perfectly for me. === $ python3.0 Python 3.0 (r30:67503, Jan 14 2009, 09:13:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type help, copyright, credits or license for more information. print ('The \This is a test \ {') The This is a test { === - shantanoo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing Problem python 3
I got the same thing with idle, but when running as a script, it's not the same, it errors. I tried it on Windows and Linux. --- [da...@arch64 Python]$ less test.py #/usr/bin/python3 print ('The \This is a test \ {') [da...@arch64 Python]$ sh test.py test.py: line 3: syntax error near unexpected token `'The \This is a test \ {'' test.py: line 3: `print ('The \This is a test \ {')' [da...@arch64 Python]$ python3 Python 3.0.1 (r301:69556, Feb 22 2009, 14:12:04) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. print ('The \This is a test \ {') The This is a test { --- However the double quotes was exactly what the doctor ordered ! :) 2009/4/29 Shantanoo Mahajan (शंतनू महाजन) shanta...@gmail.com: print ('The \This is a test \ {') ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing files
Friends, My files are like below file1 file2 RemarkRemark --- --- I have huge number of such files. I want to concatenate all files in one huge file. I could do it with a script. But i want to omit the first line (ie Remark in each file) and concatenate. How to do the same ? flist=glob.glob(*.txt) out=open('all','w') for files in flist: handle=open(flist).readlines() printout, handle -- Here i want to write only from second line. I dnt want to loop over handle here and putting all lines except the first one in another variable. Is there any fancy way of doing it. out.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing files
On Thu, Mar 26, 2009 at 10:42 AM, Bala subramanian bala.biophys...@gmail.com wrote: printout, handle -- Here i want to write only from second line. I dnt want to loop over handle here and putting all lines except the first one in another variable. Is there any fancy way of doing it. Without changing anything else, you could do it with a slice: flist=glob.glob(*.txt) out=open('all','w') for files in flist: handle=open(flist).readlines() printout, handle[1:] # start with second item (indexes start at 0, remember) and go to end out.close() -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing files
On Thu, Mar 26, 2009 at 10:56 AM, Marc Tompkins marc.tompk...@gmail.comwrote: Without changing anything else, you could do it with a slice: You should probably also close your input files when you're done with them. -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing files
Bala subramanian bala.biophys...@gmail.com wrote for files in flist: handle=open(flist).readlines() printout, handle printout, handle[1:] Should do it? You might need to handle line endings though... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing files
Use '\n'.join(handle[1:]) It will create a string from your list with newline as separator. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Bala subramanian bala.biophys...@gmail.com To: Alan Gauld alan.ga...@btinternet.com Sent: Thursday, 26 March, 2009 6:11:59 PM Subject: Re: [Tutor] printing files yes you are right, When i use the following printout, handle[1:] In the out file, it saves the lines as a list rather than as a string. How to avoid this. Bala On Thu, Mar 26, 2009 at 7:05 PM, Alan Gauld alan.ga...@btinternet.com wrote: Bala subramanian bala.biophys...@gmail.com wrote for files in flist: handle=open(flist).readlines() printout, handle printout, handle[1:] Should do it? You might need to handle line endings though... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing files
On Thu, Mar 26, 2009 at 2:58 PM, ALAN GAULD alan.ga...@btinternet.com wrote: Use '\n'.join(handle[1:]) It will create a string from your list with newline as separator. The lines from readlines() include the newlines already. When i use the following printout, handle[1:] In the out file, it saves the lines as a list rather than as a string. How to avoid this. use out.writelines(handle[1:]) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing files
Kent Johnson ken...@tds.net wrote On Thu, Mar 26, 2009 at 2:58 PM, ALAN GAULD alan.ga...@btinternet.com wrote: Use '\n'.join(handle[1:]) It will create a string from your list with newline as separator. The lines from readlines() include the newlines already. Ah, OK, I couldn't remember if readlines stripped them off or not. printout, handle[1:] In the out file, it saves the lines as a list rather than as a string. use out.writelines(handle[1:]) Or if you really want to use the print style printout, ''.join(handle[1:]) ie join the lines using an empty string. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the code of a function
wormwood_3 wormwoo...@yahoo.com wrote I am wondering if there is a way to print out the code of a defined function. Its not reliable but I think you can use func.func_code.filename func.func_code.firstlineno To find the first line of code in the original source file. Its up to you to figure out the last line though! I guess checking for the next line with equivalent indentation might work. But I'm not sure how much good it would do you... unless you were writing a debugger maybe? Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the code of a function
On Mon, 29 Dec 2008 09:18:43 - Alan Gauld alan.ga...@btinternet.com wrote: wormwood_3 wormwoo...@yahoo.com wrote I am wondering if there is a way to print out the code of a defined function. Its not reliable but I think you can use func.func_code.filename func.func_code.firstlineno To find the first line of code in the original source file. Its up to you to figure out the last line though! I guess checking for the next line with equivalent indentation might work. But I'm not sure how much good it would do you... unless you were writing a debugger maybe? Alan G I would do it so by parsing source file: * (convert indents to tabs (easier to parse)) * search for a line that start with (n indents) + def func_name * record all following lines that start with (n+1 indents) or more * stop where a line starts with (n indents) or less denis -- la vida e estranya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the code of a function
On Sun, Dec 28, 2008 at 8:49 PM, wormwood_3 wormwoo...@yahoo.com wrote: Hello all, This might be trivially easy, but I was having a hard time searching on it since all the component terms are overloaded:-) I am wondering if there is a way to print out the code of a defined function. If the source code is available try inspect.getsource(). Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing the code of a function
Hello all, This might be trivially easy, but I was having a hard time searching on it since all the component terms are overloaded:-) I am wondering if there is a way to print out the code of a defined function. So if I have: def foo(): print Show me the money. then I would like to do something like: foo.show_code def foo(): print Show me the money. I checked out everything in dir(foo), but everything that looked promising (namely foo.func_code), didn't end up being anything close. Thanks for any help! Cordially, Sam ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - http://www.flickr.com/photos/samuelhuckins/ AIM - samushack | Gtalk - samushack | Skype - shuckins ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the code of a function
wormwood_3 wrote: I am wondering if there is a way to print out the code of a defined function. When Python compiles source code, it doesn't store the source code itself; only the compiled intermediate code. With the 'dis' package you can disassemble that: def foo(): print Show me the money. import dis dis.dis(foo) 2 0 LOAD_CONST 1 ('Show me the money.') 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (None) 8 RETURN_VALUE -- The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing. - Vinod Vallopillil http://www.catb.org/~esr/halloween/halloween4.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the code of a function
wormwood_3 wrote: Hello all, This might be trivially easy, but I was having a hard time searching on it since all the component terms are overloaded:-) I am wondering if there is a way to print out the code of a defined function. Python does not store the source when compiling things. So the short answer is NO. There are some "disassemblers" for Python but I have no experience with them. They will not be able to reconstruct the exact source. But ... why do you want to do this? Perhaps if we had more information about the "use case" we could steer you to a solution. So if I have: def foo(): print "Show me the money." then I would like to do something like: foo.show_code def foo(): print "Show me the money." I checked out everything in dir(foo), but everything that looked promising (namely foo.func_code), didn't end up being anything close. Thanks for any help! Cordially, Sam ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - http://www.flickr.com/photos/samuelhuckins/ AIM - samushack | Gtalk - samushack | Skype - shuckins ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the code of a function
I actually didn't have a definite use case in mind, it was pure curiosity that arose while writing a few simple test functions. After having considered it more, I can't come up with a case where it would really be necessary, so I apologize for that. It makes sense why it wouldn't be possible without a disassembler now. Thanks for the info! ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - http://www.flickr.com/photos/samuelhuckins/ AIM - samushack | Gtalk - samushack | Skype - shuckins From: bob gailer bgai...@gmail.com To: wormwood_3 wormwoo...@yahoo.com Cc: tutor@python.org Sent: Sunday, December 28, 2008 9:07:12 PM Subject: Re: [Tutor] Printing the code of a function wormwood_3 wrote: Hello all, This might be trivially easy, but I was having a hard time searching on it since all the component terms are overloaded:-) I am wondering if there is a way to print out the code of a defined function. Python does not store the source when compiling things. So the short answer is NO. There are some disassemblers for Python but I have no experience with them. They will not be able to reconstruct the exact source. But ... why do you want to do this? Perhaps if we had more information about the use case we could steer you to a solution. So if I have: def foo(): print Show me the money. then I would like to do something like: foo.show_code def foo(): print Show me the money. I checked out everything in dir(foo), but everything that looked promising (namely foo.func_code), didn't end up being anything close. Thanks for any help! Cordially, Sam ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - http://www.flickr.com/photos/samuelhuckins/ AIM - samushack | Gtalk - samushack | Skype - shuckins ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Bob Gailer Chapel Hill NC 919-636-4239___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing concatenated unicode strings
Hello i would like to do this print u'\u30fa' ヺ with a method like this b = 30fa uni = u'\u' + b + '\'' but it prints this UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 0-1: end of string in escape sequence so how to concatenate properly to print the character ヺ I want to do this to print the characters in a loop so that b would change ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing concatenated unicode strings
Siim Märtmaa wrote: i would like to do this print u'\u30fa' ヺ with a method like this b = 30fa uni = u'\u' + b + '\'' but it prints this UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 0-1: end of string in escape sequence so how to concatenate properly to print the character ヺ I want to do this to print the characters in a loop so that b would change help (unichr) Help on built-in function unichr in module __builtin__: unichr(...) unichr(i) - Unicode character Return a Unicode string of one character with ordinal i; 0 = i = 0x10. TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing Scripts with color/good formatting
I went through a similar process: I got used to PyWin on XP, then when switching to Vista pywin did not install with Python. So I simply downloaded and installed it. (link: http://sourceforge.net/projects/pywin32/ ) Hth, Omer. On Sat, Sep 13, 2008 at 5:41 AM, Mike Meisner [EMAIL PROTECTED] wrote: I've been working with Python on two different machines: under Windows XP and under 64-bit Vista. In the XP version, the Python 32-bit editor prints my scripts using the color coding in the editor and a comfortable to read font. Under Vista 64-bit, only the IDLE environment is available which prints my scripts without color and a larger, more difficult to read font (and there appears to be no way to customize the output). Is there an open-source editor I could use with Vista to get the more attractive, color coded script printout that I get with the 32--bit system? Thanks for your help. Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing Scripts with color/good formatting
Mike Meisner [EMAIL PROTECTED] wrote In the XP version, the Python 32-bit editor I'm not sure which editor you mean? Is it Pythonwin? Is there an open-source editor I could use with Vista to get the more attractive, color coded script printout that I get with the 32--bit system? Doesn't Pythonwin work on 64 bit Vista? If not I'm fairly sure Scite does and it uses the same editor component as Pythonwin. I think its print mechanism is the same too. HTH, Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing Scripts with color/good formatting
I've been working with Python on two different machines: under Windows XP and under 64-bit Vista. In the XP version, the Python 32-bit editor prints my scripts using the color coding in the editor and a comfortable to read font. Under Vista 64-bit, only the IDLE environment is available which prints my scripts without color and a larger, more difficult to read font (and there appears to be no way to customize the output). Is there an open-source editor I could use with Vista to get the more attractive, color coded script printout that I get with the 32--bit system? Thanks for your help. Mike___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing format with list
Hi people Is there a way to use a list with printf formating without having to explicitly expanding the list after the % e.g a = [1, 2, 3] print Testing %i, %i, %i %(a[0], a[1], a[2]) Cheers Andy ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing format with list
Andy Cheesman wrote: Hi people Is there a way to use a list with printf formating without having to explicitly expanding the list after the % e.g a = [1, 2, 3] print Testing %i, %i, %i %(a[0], a[1], a[2]) It looks as though string formatting only understands tuples, not sequences in general: a = [1, 2, 3] print Testing: %i, %i, %i % tuple (a) or just: a = 1, 2, 3 print Testing: %i, %i, %i % a TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing format with list
Andy Cheesman wrote: Hi people Is there a way to use a list with printf formating without having to explicitly expanding the list after the % e.g a = [1, 2, 3] print Testing %i, %i, %i %(a[0], a[1], a[2]) The argument after % must be a tuple (or a single item) so just convert the list to a tuple: print Testing %i, %i, %i % tuple(a) or create it as a tuple to begin with if that is practical... Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [tutor] printing bitmap image dynamically reading data inwxpython
Varsha Purohit [EMAIL PROTECTED] wrote I want to create a wxpython program where i am reading a list having integer values like [1,2,3,4]. and i need to display the output value as bitmap image which shd be coloured after reading the values. Like 1=red, 2=yellow, 3=orange etc and it displays the output in colours at proper coordinates by matching values of the array. Sounds like a fun project. Have you any plans on how to go about it? Are you having problems? Or are you just sharing your excitement at the challenge? I need to make a script file for arcgis tool which converts the ascii data to a coloured bitmap image at given coordinates. I dunno much about arcgis but again it sounds like a reasonable thing to do. Let us know how you get on. If you run into problems ask questions we might be able to help. However since it seems to be a homework type exercise we can't solve it for you. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [tutor] printing bitmap image dynamically reading data inwxpython
Hi Alan, Thanks for the response. Its not a home work problem its actually a task i need to complete as i am tryin to make some tool which will be helpful to use as a script in arcgis. i kinda got some clue will surely ask help if i get stuck somewhere coz i know its difficult to put down in words of what i wanna do :( thanks, Varsha On 10/1/07, Alan Gauld [EMAIL PROTECTED] wrote: Varsha Purohit [EMAIL PROTECTED] wrote I want to create a wxpython program where i am reading a list having integer values like [1,2,3,4]. and i need to display the output value as bitmap image which shd be coloured after reading the values. Like 1=red, 2=yellow, 3=orange etc and it displays the output in colours at proper coordinates by matching values of the array. Sounds like a fun project. Have you any plans on how to go about it? Are you having problems? Or are you just sharing your excitement at the challenge? I need to make a script file for arcgis tool which converts the ascii data to a coloured bitmap image at given coordinates. I dunno much about arcgis but again it sounds like a reasonable thing to do. Let us know how you get on. If you run into problems ask questions we might be able to help. However since it seems to be a homework type exercise we can't solve it for you. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [tutor] printing bitmap image dynamically reading data in wxpython
Hello All, I want to create a wxpython program where i am reading a list having integer values like [1,2,3,4]. and i need to display the output value as bitmap image which shd be coloured after reading the values. Like 1=red, 2=yellow, 3=orange etc and it displays the output in colours at proper coordinates by matching values of the array. I need to make a script file for arcgis tool which converts the ascii data to a coloured bitmap image at given coordinates. thanks, -- Varsha Purohit, Graduate Student, San Diego State University ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing value returning from a Class
Hello friends,, I have a problem in displaying data which i have invoked from class. City is the name of the class which i havent displayed here. There is another script using that class. It has a function name setCities which takes a text file as argument. Text file contains name of the city, x and y location. there are 4 datas in 4 different lines. Code is as follows. import City def setCities(inFile): # puts city.txt content into City class objects # the field order of input file is: name x y x, y are integers. data are in newlines. f = open(inFile, 'r') body = f.readlines() f.close() cities = [] # list of cities for row in body: cityData = row.strip().split() cityName = cityData[0] cityX = cityData[1] cityY = cityData[2] newCity = City(cityName, cityX, cityY) # city class is invoked cities.append(newCity) return cities abc = setCities(C:\MS\sem5\Lab2_scripts\cities.txt) # setCities function will return the array with values read from the file. print abc I am getting output like [city.City instance at 0x023E82D8, city.City instance at 0x023E8300, city.City instance at 0x023E8350, city.City instance at 0x023E83C8] I want the data and not the instance... what should i do ?? -- Varsha Purohit, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing value returning from a Class
Hello! On 9/13/07, Varsha Purohit [EMAIL PROTECTED] wrote: Hello friends,, I have a problem in displaying data which i have invoked from class. City is the name of the class which i havent displayed here. There is another script using that class. It has a function name setCities which takes a text file as argument. Text file contains name of the city, x and y location. there are 4 datas in 4 different lines. Code is as follows. import City def setCities(inFile): # puts city.txt content into City class objects # the field order of input file is: name x y x, y are integers. data are in newlines. f = open(inFile, 'r') body = f.readlines() f.close() cities = [] # list of cities for row in body: cityData = row.strip().split() cityName = cityData[0] cityX = cityData[1] cityY = cityData[2] newCity = City(cityName, cityX, cityY) # city class is invoked cities.append(newCity) return cities abc = setCities(C:\MS\sem5\Lab2_scripts\cities.txt) # setCities function will return the array with values read from the file. print abc I am getting output like [city.City instance at 0x023E82D8, city.City instance at 0x023E8300, city.City instance at 0x023E8350, city.City instance at 0x023E83C8] I want the data and not the instance... what should i do ?? Well, that depends on the City class. When you print a list, it just calls repr() on each item in the list and prints that. Now, suppose there is a method printCity() in the City class for printing the city data. In that case you should probably just loop over the list of instances and call the method, like this: abc = setCities(city file) for city in abc: ... city.printCity() If there is no such method, maybe you can extract the data from the class and write your own printing function, or modify the class to add one. HTH, Kalle ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing HTML files
Hi I am currently trying to print out a html file that is essentially a summary table and I am running into problems. From the link below it seems that the method I am using to print the table doesn't handle column width and wrapping but confusingly we use a similar method elsewhere in the code and it works fine. This is the summary builder class TestingSummary: def __init__(self,records): self.records = records def splitRecordAndBuildSummaryText(self): summary_dict={} test_fields=[] keys=[] fields = [TestedDate:,TestId:,Branch:,Version:,SpecId:,PassOrFail:] records = self.records.split(\n\n) for record in records: record=record.split(\n) for item in record: if TestId in item: testid=record.pop(1) testid = testid.replace(TestId:,) for field in record: for item in fields: #print item field = field.replace(item,) test_fields.append(field) summary_dict[testid]=test_fields test_fields = [] # print summary_dict summary = self.buildHtmlSummaryPage(summary_dict) return summary def buildHtmlSummaryPage(self,dict_of_summary): #print list_of_ids test_summary_details= for key, value in dict_of_summary.items(): #print value #print details test_summary_details+=trtd width=11%%%s/tdtd width=18%%%s/tdtd width=12%%%s/tdtd width=29%%%s/td/tr\n % (key,value[3],value[-1],.join(value[1]+value[2])) summary = .join([htmlheadtitle/title/headbodytable border=0 width=88%\n, trtd width=24%bfont face=ArialTesting Summary/font/b/tdtd width=31%nbsp;/tdtd width=26%nbsp;/td/tr\n, trtd width=24%bfont face=Arial BlackTested by:/font/b/tdtd width=31%nbsp; /td\n, td width=26%bfont face=Arial BlackMachine Name:/font/b /td/tr\n, trtd width=24%nbsp;/tdtd width=31%nbsp;/tdtd width=26%nbsp;/td/tr\n, trtd width=24%nbsp;/tdtd width=31%nbsp;/tdtd width=26%nbsp;/td/tr\n, trtd width=11%bufont face=ArialTestID/font/u/b/tdtd width=18%bufont face=ArialSpecification/font/u/b/td\n, td width=12%bufont face=ArialResult/font/u/b/tdtd width=39%bufont face=ArialBuildID/font/u/b/td/trtr\n]) summary+=test_summary_details summary+=/body/html return summary and the mechanism for printing def printSummary(self,summary): print_dialog = wx.PrintDialog(self) if print_dialog.ShowModal() == wx.ID_CANCEL: return print_dialog_data = print_dialog.GetPrintDialogData() printer = wx.Printer(print_dialog_data) printout = wx.html.HtmlPrintout(Printing Test Summary) # margins (top, bottom, left, right) printout.SetMargins(15, 15, 20, 20) #REMOVE #-This was for testing purposes only htmlOutput = open(TestingSummary.html,w) htmlOutput.write(summary) htmlOutput.close() #- printout.SetHtmlText(summary) printout.SetFooter(self.HtmlFooterForPrint(1, 1)) printer.Print(self, printout, False) When I save the file as html the browser will open it fine and it is I expect but if I print it I end up with Testing Summary Tested by: Machine Name: TestIDSpecificationResultBuildID 03 --0009 Pass 02 Specification--0009 Pass 01 Specification--0009 Pass http://archives.devshed.com/forums/python-122/printing-problem-1843805.h tml Am I doing something silly? Thanks Dean Gardner DISCLAIMER: Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing labels
I am a Python beginner. For my first task I wanted to fix a program that I originally wrote in Excel with VBA. I want to create a mySQL database holding my DVD collection, edit it in Python, and print labels for the cases with an index for filing and a catalog of all the titles their indices. To print the labels the way I want, I will need extended control over the printer: positioning the printer precisely and changing fonts, colors, and background colors. Is there a public python library that could give me this level of control? Thanks Steve ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing labels
Steve Maguire wrote: I am a Python beginner. For my first task I wanted to fix a program that I originally wrote in Excel with VBA. I want to create a mySQL database holding my DVD collection, edit it in Python, and print labels for the cases with an index for filing and a catalog of all the titles their indices. To print the labels the way I want, I will need extended control over the printer: positioning the printer precisely and changing fonts, colors, and background colors. Is there a public python library that could give me this level of control? Best bet is probably using Reportlab (http://reportlab.org) to generate PDF. Their platypus layout scheme is very flexible, and you may even find someone's already done labels as an example. TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing txt files in landscape from python
Hi All, do you have any idea, how I can send a txt file to the default printer in landscape view with python on windows. I wanted to set up just the char size and the orientation of the printout. thinking about os.system('notepad.exe /pt %%%s' % filename) Yours sincerely, __ János Juhász ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing txt files in landscape from python
János Juhász schrieb: do you have any idea, how I can send a txt file to the default printer in landscape view with python on windows. I assume that by txt file, you mean a file containing ASCII text? I wanted to set up just the char size and the orientation of the printout. Printers normally don't understand ASCII file sent to them, unless you configure them (with some status codes) to do so. Normally, the OS converts a text file sent to its printing system to something the printer understands, like PostScript or PL5/6, and allows you to set other options, e.g. setting landscape mode or choosing the paper tray. Under windows, this is what the printer drivers are for, under MAC OS X and Linux, this is done by the CUPS system. Unfortunately, the specifics depend highly on the system, the printer driver, the printer and the application that sends the file to the print system. thinking about os.system('notepad.exe /pt %%%s' % filename) So this is actually your safest bet, but will only work under windows obviously. Under Linux, you could try to use the 'a2ps' programm, but it is not installed everywhere. Chris ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing txt files in landscape from python
Hi All, do you have any idea, how I can send a txt file to the default printer in landscape view with python on windows. I wanted to set up just the char size and the orientation of the printout. thinking about os.system('notepad.exe /pt %%%s' % filename) Doesn't completely answer your question, but have a look at this: http://timgolden.me.uk/python/win32_how_do_i/print.html and perhaps consider a ReportLab solution. It's ridiculously difficult to set up the printing params construct under Windows (just search for DEVMODE) so might well be easier to use a PDF approach. TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing txt files in landscape from python
On Thu, 1 Feb 2007, [ISO-8859-1] J?nos Juh?sz wrote: do you have any idea, how I can send a txt file to the default printer in landscape view with python on windows. I wanted to set up just the char size and the orientation of the printout. I've gotten a crush on wxPython, now that it's nicely documented in the wxPython in Action book. Take a look at http://wiki.wxpython.org/index.cgi/Printing for a discussion of printing. Here's an example on printing, copying the code from Code Sample - Easy Printing on that page. ### # this part copied from URL above: from wx.html import HtmlEasyPrinting class Printer(HtmlEasyPrinting): def __init__(self): HtmlEasyPrinting.__init__(self) def GetHtmlText(self,text): Simple conversion of text. Use a more powerful version html_text = text.replace('\n\n','P') html_text = text.replace('\n', 'BR') return html_text def Print(self, text, doc_name): self.SetHeader(doc_name) self.PrintText(self.GetHtmlText(text),doc_name) def PreviewText(self, text, doc_name): self.SetHeader(doc_name) HtmlEasyPrinting.PreviewText(self, self.GetHtmlText(text)) # now, using it: text_to_print = Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the government for a redress of grievances. app = wx.PySimpleApp() p = Printer() p.Print(text_to_print, Amend 1) ### This works, and gives you (well, the user) the option of printing landscape. I'm not sure how to go about specifying a font. I suspect you'll have to go with the more heavyweight Code Sample - `(wx)Printout` Printing examplefor that. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing 00
+++ Christopher Spears [10-07-06 21:34 -0700]: | I'm working on a problem from How To Think Like A | Computer Scientist. I created a Time class: | | class Time: | | def __init__(self, hours, minutes, seconds): | self.hours = hours | self.minutes = minutes | self.seconds = seconds | | I created a function to print the Time object: | | def printTime(time): | print %d:%d:%d % (time.hours, time.minutes, | time.seconds) | | However, when I type '00', I get the following: | time = Time(12,34.4,00) | printTime(time) | 12:34:0 | time.seconds | 0 instead of %d you may use %02d. Shantanoo -- It's not what you look at that matters, it's what you see. ~Henry David Thoreau ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing 00
I'm working on a problem from How To Think Like A Computer Scientist. I created a Time class: class Time: def __init__(self, hours, minutes, seconds): self.hours = hours self.minutes = minutes self.seconds = seconds I created a function to print the Time object: def printTime(time): print %d:%d:%d % (time.hours, time.minutes, time.seconds) However, when I type '00', I get the following: time = Time(12,34.4,00) printTime(time) 12:34:0 time.seconds 0 How do I get around this problem? I know there is a time module. However, I think that is overkill for this particular assignment. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing 00
I created a function to print the Time object: def printTime(time): print %d:%d:%d % (time.hours, time.minutes, time.seconds) However, when I type '00', I get the following: time = Time(12,34.4,00) printTime(time) 12:34:0 Hi Chris, You'll want to check some of the details on String Formatting -- there's an option to format a number using two (or more) digits: http://www.python.org/doc/lib/typesseq-strings.html Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing the links of a page (regular expressions)
I'm writing a script to retrieve and print some links of a page. These links begin wiht /dog/, so I use a regular expresion to try to find them. The problem is that the script only retrieves a link per line in the page. I mean, if the line hat several links, the script only reports the first. I can't find where is the mistake. Does anyone hat a idea, what I have false made? Thank you very much for your help. import re from urllib import urlopen fileObj = urlopen(http://name_of_the_page;) links = [] regex = re.compile ( ((/dog/)[^ \\';:,]+),re.I) for a in fileObj.readlines(): result = regex.search(a) if result: print result.group() __ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing the links of a page (regular expressions)
Alfonso wrote: I'm writing a script to retrieve and print some links of a page. These links begin wiht /dog/, so I use a regular expresion to try to find them. The problem is that the script only retrieves a link per line in the page. I mean, if the line hat several links, the script only reports the first. I can't find where is the mistake. Does anyone hat a idea, what I have false made? You are reading the data by line using readlines(). You only search each line once. regex.findall() or regex.finditer() would be a better choice than regex.search(). You might also be interested in sgmllib-based solutions to this problem, which will generally be more robust than regex-based searching. For example, see http://diveintopython.org/html_processing/extracting_data.html http://www.w3journal.com/6/s3.vanrossum.html#MARKER-9-26 Kent Thank you very much for your help. import re from urllib import urlopen fileObj = urlopen(http://name_of_the_page;) links = [] regex = re.compile ( ((/dog/)[^ \\';:,]+),re.I) for a in fileObj.readlines(): result = regex.search(a) if result: print result.group() __ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing the links of a page (regular expressions)
Kent Johnson wrote: Alfonso wrote: I'm writing a script to retrieve and print some links of a page. These links begin wiht /dog/, so I use a regular expresion to try to find them. The problem is that the script only retrieves a link per line in the page. I mean, if the line hat several links, the script only reports the first. I can't find where is the mistake. Does anyone hat a idea, what I have false made? You are reading the data by line using readlines(). You only search each line once. regex.findall() or regex.finditer() would be a better choice than regex.search(). You might also be interested in sgmllib-based solutions to this problem, which will generally be more robust than regex-based searching. For example, see http://diveintopython.org/html_processing/extracting_data.html http://www.w3journal.com/6/s3.vanrossum.html#MARKER-9-26 Kent Thank you very much for your help. import re from urllib import urlopen fileObj = urlopen(http://name_of_the_page;) links = [] regex = re.compile ( ((/dog/)[^ \\';:,]+),re.I) for a in fileObj.readlines(): result = regex.search(a) if result: print result.group() __ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Thank you very much, Kent, it works with findall(). I will also have a look at the links about sgmllib. __ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the Carriage return character
Not sure if this is a python thing or a Operating system peculiarity, An IDLE thing specifically - or maybe even a Tkinter thing... Why does the line print FirstLine + \rSecondLine produce different output when run via IDLE and when run in the python prompt (both under Windows XP)? \r is a carriage return which literally means that the printhead carriage should return to the start of the line. You need a line feed character if you want a new line too. Unfortunately some OS use \r to do both, others need both. The safe way is to use \n (new line) instead. Output in IDLE (ver 1.1.1, python 2.4.1): FirstLine SecondLine Output at the python prompt (python 2.4.1): SecondLine So being pedantic XP is correct, IDLE is wrong but in fact because the conventions are so mixed up right and wrong is a bit woolly. Which response were you trying to get? Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing the Carriage return character
Thanks Alan for clearing that up...I was trying to see why my \r\n does not print 2 empty lines when I stumbled across this 'gotcha'. -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Monday, 20 February 2006 9:22 p.m. To: Hans Dushanthakumar; tutor@python.org Subject: Re: [Tutor] Printing the Carriage return character Not sure if this is a python thing or a Operating system peculiarity, An IDLE thing specifically - or maybe even a Tkinter thing... Why does the line print FirstLine + \rSecondLine produce different output when run via IDLE and when run in the python prompt (both under Windows XP)? \r is a carriage return which literally means that the printhead carriage should return to the start of the line. You need a line feed character if you want a new line too. Unfortunately some OS use \r to do both, others need both. The safe way is to use \n (new line) instead. Output in IDLE (ver 1.1.1, python 2.4.1): FirstLine SecondLine Output at the python prompt (python 2.4.1): SecondLine So being pedantic XP is correct, IDLE is wrong but in fact because the conventions are so mixed up right and wrong is a bit woolly. Which response were you trying to get? Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing the Carriage return character
Hi, Not sure if this is a python thing or a Operating system peculiarity, but here goes: Why does the line print FirstLine + \rSecondLine produce different output when run via IDLE and when run in the python prompt (both under Windows XP)? Output in IDLE (ver 1.1.1, python 2.4.1): print FirstLine + \rSecondLine FirstLine SecondLine Output at the python prompt (python 2.4.1): C:\QVCS\Mobile Data\python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. print FirstLine + \rSecondLine SecondLine Cheers Hans ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing the random seed?
Danny Yoo wrote: On Thu, 2 Feb 2006, kevin parks wrote: Danny (hope you are good!) co, I see that biz about random.seed()... but in the absence of setting that ... does it just grab a value from the system clock? Yes. Here's what the documentation says officially: current system time is also used to initialize the generator when the module is first imported As of Python 2.4, random.seed() will attempt to use os.urandom() to initialize the seed; if that is not available it uses the system time. Is there a way to just let it generate it's usual, known seed... but then observe what that is in case you get an especially good run of data? We can call seed() explicitely using system time then when we start using the random module, and if the results are interesting, we report that initial seed value too. That way, by knowing the initial conditions, we can reproduce the results. Here is the code from random.py that initializes the seed (a): try: a = long(_hexlify(_urandom(16)), 16) except NotImplementedError: import time a = long(time.time() * 256) # use fractional seconds Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing the random seed?
hi. I am having some fun with python and making multiple runs on an algorhythm and sometimes getting some fun stuff that i would like to be able to reproduce, but there are some random elements in it. I wonder is there a way to see the random seed, and make note of it so that you could then set the seed for a subsequent run to get the same (initially) random results? cheers, kevin (Hi Danny, if you are still here!) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing the random seed?
I am having some fun with python and making multiple runs on an algorhythm and sometimes getting some fun stuff that i would like to be able to reproduce, but there are some random elements in it. I wonder is there a way to see the random seed, and make note of it so that you could then set the seed for a subsequent run to get the same (initially) random results? Hi Kevin, Sure; take a look at the seed() function in the random module. http://www.python.org/doc/lib/module-random.html#l2h-1298 Just set it to some consistant value at the very beginning of your program, and you should then see duplicate results between program runs. You could also probably do something with random.getstate() and random.setstate(), but it's probably a bit simpler just to inject a known seed value into the pseudorandom generator. (Hi Danny, if you are still here!) *wave wave* Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing the random seed?
Danny (hope you are good!) co, I see that biz about random.seed()... but in the absence of setting that ... does it just grab a value from the system clock? Is there a way to just let it generate it's usual, known seed... but then observe what that is in case you get an especially good run of data? like i clearly can't just go: zeed = random.seed() print zeed = , zeed hmm... cheers, -[kp]-- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing the random seed?
On Thu, 2 Feb 2006, kevin parks wrote: Danny (hope you are good!) co, I see that biz about random.seed()... but in the absence of setting that ... does it just grab a value from the system clock? Yes. Here's what the documentation says officially: current system time is also used to initialize the generator when the module is first imported Is there a way to just let it generate it's usual, known seed... but then observe what that is in case you get an especially good run of data? We can call seed() explicitely using system time then when we start using the random module, and if the results are interesting, we report that initial seed value too. That way, by knowing the initial conditions, we can reproduce the results. ## import time import random t = time.time() random.seed(t) random.random() 0.39026231885512619 random.random() 0.72296902513427053 random.random() 0.48408173490166762 t 1138866167.719857 random.seed(t) random.random() 0.39026231885512619 random.random() 0.72296902513427053 random.random() 0.48408173490166762 ## ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing in Windows (was: Further help needed!
I've edited the subject line to be a little more clear. On Wed, 4 Jan 2006, John Corry wrote: I am using the following code to send a text file to the printer:- [ snip ] This code works on windows XP + Windows 2000. However it does not work on windows 98SE. Well, at least that narrows it down. This continues to befuddle me. I don't know enough about Windows to know the differences that might be here for this purpose. Question: do you need to use the Windows print function, or can you live with printing it yourself (as below)? For example, if you use the ShellExecute approach, it actually causes an application to be invoked for you, which does the printing, just as if you right-clicked on the file and selected print. ON my system, for example, that will invoke Notepad, which prints it with a heading and a page number at the bottom. But, if you don't care about that, assuming your file is straight text, try the win32print approach from http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html . Here's an attempt that seems to work for me: --- import win32print lines_to_print = open(testprint.txt,r).readlines() print_data = '' for line in lines_to_print: print_data=''.join([print_data,line,\r]) printer_name = win32print.GetDefaultPrinter() printer = win32print.OpenPrinter(printer_name) print_job = win32print.StartDocPrinter(printer, 1, (Printer test, None, RAW)) win32print.WritePrinter(printer, print_data) win32print.EndDocPrinter(printer) win32print.ClosePrinter(printer) --- The for-loop is a kludge; my first attempt was something like print_data=open(testprint.txt,r).read() but it turns out my printer needs a carriage return on each line. I suspect that printer handling is more likely to be inconsistent between Win98 and Win/XP than the ShellExecute you were already using, and so this may not work; but it's worth looking into. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing in Windows (was: Further help needed!
On Wed, 4 Jan 2006, John Corry wrote: I am using the following code to send a text file to the printer:- This code works on windows XP + Windows 2000. However it does not work on windows 98SE. Here's another alternative, which might be even simpler, if it works for you, invoking the good old-fashioned DOS print command: import os filename = testprint.txt commandline = print + filename os.popen(commandline) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing error on Win 98SE
Hi + Happy New Year, With help from several people from the mailing list I have been able to print out text files on my windows XP machine. I have tried using the same program on my windows 98SE machine and I get the following error: PythonWin 2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) - see 'Help/About PythonWin' for further copyright information. Traceback (most recent call last): File C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py, line 310, in RunScript exec codeObject in __main__.__dict__ File C:\test\Script1.py, line 12, in ? 0 error: (31, 'ShellExecute', 'A device attached to the system is not functioning.') I can manually right click the text file and left click print and the file will print to the printer. The code that I am using is below: import win32api filename = testprint.txt fileobj=open (filename, w) fileobj.write (This is a test) fileobj.close() win32api.ShellExecute ( 0, print, filename, None, ., 0 ) Any help would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
"John Corry" [EMAIL PROTECTED] 12/24/2005 12:28 PM Hi + Season's Greetings!I have put together a program that queries and modifies a Gadfly database.I have captured my output. I now want to print it to paper.I have written the output to a text file. I have searched the tutor mailinglist and used the mailing list advice to get my data into nice lookingcolumns + tables.I am using Python 2.4, Glade 2, pygtk2.8.0 + wxWidgets2.6.1.I have downloaded win32, win32com, Preppy and PIL. I have had a go at usingthem but can't get them to work. At the moment I can't even print the textfile.Is there a good helpguide/FAQ page which deals with printing text files oris there simple code which prints a text file?Thanks,John.You might want to look at karrigell ( http://karrigell.sourceforge.net/ ) and consider making your output an html text file, styled with css, that you can view/print using the browser. I think karrigell is simple for desktop apps - - certainly simpler than wxWidgets, etc.TurboGears ( http://www.turbogears.org ) is more oriented toward a full website. Both frameworks are built on CherryPy, which is coming on strong as a full-featured, lightweight 'Pythonic" server.I like to use the browser for output because it does so much of the formatting for you and it's cross-platform, and I like using a framework because if you ever want to use your program over the web, you're nearly done. Ron ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
On Mon, 26 Dec 2005, John Corry wrote: Thanks for the prompt reply. This is exactly what I am looking for. However, I have tried the code on the page and I can't get it to work. ... Traceback (most recent call last): File c:\python24\jhc.py, line12, in ? 0 pywintypes.error: (2, 'ShellExecute', 'The system cannot find the file specified .') Odd. Works for me. Just for the heck of it, try using a known filename, instead of making a randomly-named one, and try closing the file first: import win32api filename = testprint.txt fileobj=open (filename, w) fileobj.write (This is a test) fileobj.close() win32api.ShellExecute ( 0, print, filename, None, ., 0 ) Then you can confirm at least, that your file is being created. What version python are you using? I'm using activestate's: C:\test\printpython ActivePython 2.4.1 Build 245 (ActiveState Corp.) based on Python 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
On Tue, 27 Dec 2005, John Corry wrote: I am saving the code to c:\python24\jhc2.py The code creates the file c:\python24\testprint.txt John, I would *very* strongly advise not to store your code in c:\python24 or any subdirectory in it. That is where Python itself lives, and it's very possible that you could create a file with the same name as a Python-supplied file, and the file you create will start getting erroneously used instead of the correct one. I don't know that this is your problem, but it's certainly a factor I would eliminate. Can you tell us what other files, and their names, you may have added there? I have a directory named C:\test where I do my coding. I generally create a subdirectory with some memorable name and work there. For example, for testing your problem out, I have C:\ test\ print\ testpr.py testpr2.py testprint.txt There may be some differences between what's installed in your Python installation and in mine. I'm a big fan of Activestate's ActivePython. It includes most of the Win32-specific stuff you'll need already. You may end up needing to re-install Python if you've put too much into the Python24 directory; if so, I'd suggest you re-install from the Activestate version. It's also free, and made to target Windows. I don't know of any downsides to using it instead of the Windows release from Python.org, and it just works. http://www.activestate.com/Products/ActivePython/?pysbx=1 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
At 08:52 AM 12/26/2005, John Corry wrote: Thanks for the prompt reply. This is exactly what I am looking for. However, I have tried the code on the page and I can't get it to work. import tempfile import win32api filename = tempfile.mktemp (.txt) open (filename, w).write (This is a test) win32api.ShellExecute ( 0, print, filename, None, ., 0 ) Also beware that the file must have an extension associated with an application that recognizes the print command. e.g. if the file is named foo.doc and .doc is registered as belonging to MS Word, then this will open MSword, open the file, print the file and close Word. It is the equivalent of right-clicking the file in the explorer and then choosing Print from the context menu. I am using the Pythoncard code editor and I get the following error: Traceback (most recent call last): File c:\python24\jhc.py, line12, in ? 0 pywintypes.error: (2, 'ShellExecute', 'The system cannot find the file specified .') I have played about with it and saved it in various places but I can't get it to work. Any suggestions? Do I need to import other modules? Do I need to use Pythonwin? Thanks, John. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Danny Yoo Sent: 24 December 2005 19:33 To: John Corry Cc: Tutor Subject: Re: [Tutor] Printing I have downloaded win32, win32com, Preppy and PIL. I have had a go at using them but can't get them to work. At the moment I can't even print the text file. Is there a good helpguide/FAQ page which deals with printing text files or is there simple code which prints a text file? Hi John, Let's see... ok, found it! Tim Golden has written a small introduction to printing: http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html His recommendation is to use the ShellExecute function in win32api to send off documents to your printer. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
Thanks for the prompt reply. This is exactly what I am looking for. However, I have tried the code on the page and I can't get it to work. import tempfile import win32api filename = tempfile.mktemp (.txt) open (filename, w).write (This is a test) win32api.ShellExecute ( 0, print, filename, None, ., 0 ) I am using the Pythoncard code editor and I get the following error: Traceback (most recent call last): File c:\python24\jhc.py, line12, in ? 0 pywintypes.error: (2, 'ShellExecute', 'The system cannot find the file specified .') I have played about with it and saved it in various places but I can't get it to work. Any suggestions? Do I need to import other modules? Do I need to use Pythonwin? Thanks, John. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Danny Yoo Sent: 24 December 2005 19:33 To: John Corry Cc: Tutor Subject: Re: [Tutor] Printing I have downloaded win32, win32com, Preppy and PIL. I have had a go at using them but can't get them to work. At the moment I can't even print the text file. Is there a good helpguide/FAQ page which deals with printing text files or is there simple code which prints a text file? Hi John, Let's see... ok, found it! Tim Golden has written a small introduction to printing: http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html His recommendation is to use the ShellExecute function in win32api to send off documents to your printer. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing
Hi + Season's Greetings! I have put together a program that queries and modifies a Gadfly database. I have captured my output. I now want to print it to paper. I have written the output to a text file. I have searched the tutor mailing list and used the mailing list advice to get my data into nice looking columns + tables. I am using Python 2.4, Glade 2, pygtk2.8.0 + wxWidgets2.6.1. I have downloaded win32, win32com, Preppy and PIL. I have had a go at using them but can't get them to work. At the moment I can't even print the text file. Is there a good helpguide/FAQ page which deals with printing text files or is there simple code which prints a text file? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
I have downloaded win32, win32com, Preppy and PIL. I have had a go at using them but can't get them to work. At the moment I can't even print the text file. Is there a good helpguide/FAQ page which deals with printing text files or is there simple code which prints a text file? Hi John, Let's see... ok, found it! Tim Golden has written a small introduction to printing: http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html His recommendation is to use the ShellExecute function in win32api to send off documents to your printer. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
John Corry wrote: Hi + Season's Greetings! I have put together a program that queries and modifies a Gadfly database. I have captured my output. I now want to print it to paper. I have written the output to a text file. I have searched the tutor mailing list and used the mailing list advice to get my data into nice looking columns + tables. I am using Python 2.4, Glade 2, pygtk2.8.0 + wxWidgets2.6.1. wxWidgets has support for printing, though I have never used it. See http://wxwidgets.org/manuals/2.5.3/wx_printingoverview.html#printingoverview Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing regular expression match
Dear group, I have two lists: a ['apple', 'boy', 'boy', 'apple'] b ['Apple', 'BOY', 'APPLE-231'] for i in a: pat = re.compile(i,re.IGNORECASE) for m in b: if pat.match(m): print m Apple APPLE-231 BOY BOY Apple APPLE-231 Here I tried to match element in list a to element in list b and asked to ignore the case. It did work. However, I do not know how to make it print only m What I want : Apple BOY APPLE-231 I do not want python to print both elenents from lists a and b. I just want only the elements in the list B. how can i do that.. Please help me. thank you. srini __ Yahoo! DSL Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing regular expression match
On Sat, 3 Dec 2005, Srinivas Iyyer wrote: a ['apple', 'boy', 'boy', 'apple'] b ['Apple', 'BOY', 'APPLE-231'] for i in a: pat = re.compile(i,re.IGNORECASE) for m in b: if pat.match(m): print m Hi Srinivas, We may want to change the problem so that it's less focused on printing results directly. We can rephrase the question as a list filtering operation: we want to keep the elements of b that satisfy a certain criteron. Let's give a name to that criterion now: ## def doesNameMatchSomePrefix(word, prefixes): Returns True if the input word is matched by some prefix in the input list of prefixes. Otherwise, returns False. # ... fill me in ## Can you write doesNameMatchSomePrefix()? In fact, you might not even need regexes to write an initial version of it. If you can write that function, then what you're asking: I do not want python to print both elenents from lists a and b. I just want only the elements in the list B. should not be so difficult: it'll be a straightforward loop across b, using that helper function. (Optimization can be done to make doesNameMatchSomePrefix() fast, but you probably should concentrate on correctness first. If you're interested in doing something like this for a large number of prefixes, you might be interested in: http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/ which has more details and references to specialized modules that attack the problem you've shown us so far.) Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing regular expression match
Hi Danny, thanks for your email. In the example I've shown, there are no odd elements except for character case. In the real case I have a list of 100 gene names for Humans. The human gene names are conventioanlly represented in higher cases (eg.DDX3X). However, NCBI's gene_info dataset the gene names are reported in lowercase (eg. ddx3x). I want to extract the rest of the information for DDX3X that I have from NCBI's file (given that dataset is in tab delim format). my approach was if i can define DDX3X is identical ddx3x then I want to print that line from the other list (NCBI's gene_info dataset). I guess, I understood your suggestion wrongly. In such case, why do I have to drop something from list b (which is over 150 K lines). If I can create a sublist of all elements in b (a small list of 100) then it is more easy. this is my opinion. -srini --- Danny Yoo [EMAIL PROTECTED] wrote: On Sat, 3 Dec 2005, Srinivas Iyyer wrote: a ['apple', 'boy', 'boy', 'apple'] b ['Apple', 'BOY', 'APPLE-231'] for i in a: pat = re.compile(i,re.IGNORECASE) for m in b: if pat.match(m): print m Hi Srinivas, We may want to change the problem so that it's less focused on printing results directly. We can rephrase the question as a list filtering operation: we want to keep the elements of b that satisfy a certain criteron. Let's give a name to that criterion now: ## def doesNameMatchSomePrefix(word, prefixes): Returns True if the input word is matched by some prefix in the input list of prefixes. Otherwise, returns False. # ... fill me in ## Can you write doesNameMatchSomePrefix()? In fact, you might not even need regexes to write an initial version of it. If you can write that function, then what you're asking: I do not want python to print both elenents from lists a and b. I just want only the elements in the list B. should not be so difficult: it'll be a straightforward loop across b, using that helper function. (Optimization can be done to make doesNameMatchSomePrefix() fast, but you probably should concentrate on correctness first. If you're interested in doing something like this for a large number of prefixes, you might be interested in: http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/ which has more details and references to specialized modules that attack the problem you've shown us so far.) Good luck! __ Yahoo! DSL Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing statement
At 10:02 PM 11/3/2005, Johan Geldenhuys wrote: Found it. This is what I was looking for: print ('file'+'dir'.center(20))+('\n'+'='*15) file dir === I am glad you found what you wanted. I'm sad that you did not tell us more precisely what you wanted, as we could have steered you in that direction. center() puts spaces to the right of dir. It that part of what you wanted, or just a side effect.? I'd find less () easier to read: print 'file'+'dir'.center(20)+'\n'+'='*15 and 2 print statements even better: print 'file'+'dir'.center(20) print '*15 It's actually a string operator 'center(width)' that I was looking for. I saw the '%', but that is what I wanted to use. Do you also appreciate the power of %? I hope you learn to use it also. [snip] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing statement
Hi all, Just a quick question; How do I code this output: files dirs == I want to print something a few space away from the left side or in the middle of the line. Thanks, Johan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing statement
At 11:31 AM 11/3/2005, Johan Geldenhuys wrote: Hi all, Just a quick question; How do I code this output: files dirs == I want to print something a few space away from the left side or in the middle of the line. In the Python Library Reference look up 2.3.6.2 String Formatting Operations - % interpolation In general you create a template of the desired output with %s (or other conversion type) wherever you want a value substituted. %-15s%-15s % ('files', 'dirs') will give files dirs %-15s%-15s % (filename, directory) will give funny.doc c:\root assuming the variabies filename, directory have the values shown. the - means left align, 15 is field width. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing statement
At 11:31 AM 11/3/2005, Johan Geldenhuys wrote: Hi all, Just a quick question; FWIW saying that does not help. It takes time to read it, and I can judge the question length by reading the question. The real concern is what does it take to construct an answer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing statement
bob wrote: At 11:31 AM 11/3/2005, Johan Geldenhuys wrote: Hi all, Just a quick question; How do I code this output: files dirs == I want to print something a few space away from the left side or in the middle of the line. In the Python Library Reference look up 2.3.6.2 String Formatting Operations - % interpolation In general you create a template of the desired output with %s (or other conversion type) wherever you want a value substituted. %-15s%-15s % ('files', 'dirs') will give files dirs %-15s%-15s % (filename, directory) will give funny.doc c:\root assuming the variabies filename, directory have the values shown. the - means left align, 15 is field width. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Have you considered the % formatting operator? See 2.3.6.2 String Formatting Operations in the Library Reference. Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing statement
Found it. This is what I was looking for: """ print ('file'+'dir'.center(20))+('\n'+'='*15) file dir === """ It's actually a string operator 'center(width)' that I was looking for. I saw the '%', but that is wahat I wanted to use. Johan Colin J. Williams wrote: bob wrote: At 11:31 AM 11/3/2005, Johan Geldenhuys wrote: Hi all, Just a quick question; How do I code this output: """ files dirs == """ I want to print something a few space away from the left side or in the middle of the line. In the Python Library Reference look up 2.3.6.2 String Formatting Operations - % interpolation In general you create a "template" of the desired output with %s (or other conversion type) wherever you want a value substituted. "%-15s%-15s" % ('files', 'dirs') will give "files dirs " "%-15s%-15s" % (filename, directory) will give "funny.doc c:\root " assuming the variabies filename, directory have the values shown. the - means left align, 15 is field width. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Have you considered the % formatting operator? See 2.3.6.2 String Formatting Operations in the Library Reference. Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing an acronym (fwd)
Forwarding to tutor -- Forwarded message -- Date: Mon, 26 Sep 2005 08:32:02 -0500 From: Jason Massey [EMAIL PROTECTED] To: Danny Yoo [EMAIL PROTECTED] Subject: Re: [Tutor] printing an acronym Something like this: def acro(a): ... b = a.split() ... c = ... for d in b: ... c+=d[0].upper() ... return c other than the horrible variable naming, it works. acro('international business machines') 'IBM' On 9/25/05, Danny Yoo [EMAIL PROTECTED] wrote: On Sat, 24 Sep 2005 [EMAIL PROTECTED] wrote: How could I get the following to print out an acronym for each phrase entered such as if I entered random access memory it word print out RAM? Hello, Just out of curiosity, are you already familiar with Python's lists? If so, then you might want to try the slightly easier problem of pulling out acronyms out of a list of words. Extracting an acronym out of a list like: [International, Business, Machines] == IBM is not too bad, and is one step toward doing the original problem on the phrase International Business Machines. Tutorials like: http://www.freenetpages.co.uk/hp/alan.gauld/tutseq2.htm and the other tutorials on: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers should talk about lists. Please feel free to ask questions here! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing an acronym (fwd)
Or a shorter version, a=lambda n: "".join([x[0].upper() for x in n.split()]) Then it is just: a('random access memory') 'RAM' Danny Yoo wrote: Forwarding to tutor -- Forwarded message -- Date: Mon, 26 Sep 2005 08:32:02 -0500 From: Jason Massey [EMAIL PROTECTED] To: Danny Yoo [EMAIL PROTECTED] Subject: Re: [Tutor] printing an acronym Something like this: def acro(a): ... b = a.split() ... c = "" ... for d in b: ... c+=d[0].upper() ... return c other than the horrible variable naming, it works. acro('international business machines') 'IBM' On 9/25/05, Danny Yoo [EMAIL PROTECTED] wrote: ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing an acronym
On Sat, 24 Sep 2005 [EMAIL PROTECTED] wrote: How could I get the following to print out an acronym for each phrase entered such as if I entered random access memory it word print out RAM? Hello, Just out of curiosity, are you already familiar with Python's lists? If so, then you might want to try the slightly easier problem of pulling out acronyms out of a list of words. Extracting an acronym out of a list like: [International, Business, Machines] == IBM is not too bad, and is one step toward doing the original problem on the phrase International Business Machines. Tutorials like: http://www.freenetpages.co.uk/hp/alan.gauld/tutseq2.htm and the other tutorials on: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers should talk about lists. Please feel free to ask questions here! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing an acronym
Hello How could I get the following to print out an acronym for each phrase entered such as if I entered random access memory it word print out RAM? import string def main(): phrase = (raw_input(Please enter a phrase:)) acr1 = string.split(phrase) acr2 = string.capwords(phrase) acr3 = acr2[0] print,acr3 main() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing an acronym
Hello How could I get the following to print out an acronym for each phrase entered such as if I entered random access memory it word print out RAM? import string def main(): phrase = (raw_input(Please enter a phrase:)) acr1 = string.split(phrase) acr2 = string.capwords(phrase) acr3 = acr2[0] print,acr3 main() What does it currently print? The typical way would be to use a for loop on acr1. Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing documents
hello, I am writing a program to store name/contact/business transaction information. I would like the ability to print out a form for each client with all this stored information. Can somone point me in the write direction for printing documents. How do I go about setting up a printable page with all the variables I have for each client? thanks Also I would like to take the information I input and store it as an images. Essentially take the above mentioned document (the one I want to print out a hard copy) and save it as an image so I can view it later. Any ideas? I'm operating on windows and I'm using wxpython. thanks. Jeff___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing documents
I am writing a program to store name/contact/business transaction information. I would like the ability to print out a form for each client with all this stored information. Can somone point me in the write direction for printing documents. I usually just create html files. PDF would work too but is less programmer friendly in native form. Also I would like to take the information I input and store it as an images. Essentially take the above mentioned document In that case I'd go with a PDF file which does both jobs in one and batch printing can be done from Acrobat using: http://www.reportlab.org/rl_toolkit.html to create the PDF and the /p flag in acrobat. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing out a box of O's
Kevin schrieb: I just started getting in to python and for taking a look at the for loop. I want to print out a box of O's 10o chars long by 10 lines long this is what I came up with. Is there a better way to do this: j = 'O' for i in j*10: print i * 100 Thanks Kevin Hi Kevin, I don't know, if this is better, but at least it's shorter: print ('O' * 100 + '\n') * 10 Rainer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] printing out a box of O's
I just started getting in to python and for taking a look at the for loop. I want to print out a box of O's 10o chars long by 10 lines long this is what I came up with. Is there a better way to do this: j = 'O' for i in j*10: print i * 100 Thanks Kevin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing out a box of O's
for y in range(10): for x in range(10): print O, print '\n' Or - for y in range(10): print O*10 On Mon, 28 Feb 2005 18:35:08 -0600, Kevin [EMAIL PROTECTED] wrote: I just started getting in to python and for taking a look at the for loop. I want to print out a box of O's 10o chars long by 10 lines long this is what I came up with. Is there a better way to do this: j = 'O' for i in j*10: print i * 100 Thanks Kevin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing out a box of O's
- Original Message - From: Kevin [EMAIL PROTECTED] To: tutor@python.org Sent: Tuesday, March 01, 2005 12:35 AM Subject: [Tutor] printing out a box of O's there a better way to do this: j = 'O' for i in j*10: print i * 100 Its not bad, but the for loop could be 'simplified' to: for i in range(10): print j*100 its not any shorter and probably doesn't run much faster but its a lot more readable because its the conventional Python idiom for coding fixed length loops. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing columns of data
Title: Printing columns of data Hello all, I am writing a program to take a data file, divide it up into columns and print the information back with headers. The data files looks like this 0.0 -3093.44908 -3084.59762 387.64329 26.38518 0.3902434E+00 -0.6024320E-04 0.4529416E-05 1.0 -3094.09209 -3084.52987 391.42288 105.55994 0.3889897E+00 -0.2290866E-03 0.4187074E-03 2.0 -3094.59358 -3084.88826 373.64911 173.44885 0.3862430E+00 -0.4953443E-03 0.2383621E-02 etc 10.0 ... So I wrote the program included below and it only prints the last line of the file. Timestep PE 10.0 -3091.80609 I have one question. Do I need to put ts and pe into a list before I print then to screen or I am just missing something. Thanks. Ara import string inp = open(fort.44,r) all_file = inp.readlines() inp.close() outp = open(out.txt,w) cols = map(string.split,all_file) ##print cols Data = ""> for line in cols: ts = line[0] # print line[0] pe = line[1] # print line[1] print Timestep PE print %s %s % (ts,pe) outp.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing columns of data
Kooser, Ara S wrote: Hello all, I am writing a program to take a data file, divide it up into columns and print the information back with headers. The data files looks like this 0.0 -3093.44908 -3084.59762 387.6432926.38518 0.3902434E+00 -0.6024320E-04 0.4529416E-05 1.0 -3094.09209 -3084.52987 391.42288 105.55994 0.3889897E+00 -0.2290866E-03 0.4187074E-03 2.0 -3094.59358 -3084.88826 373.64911 173.44885 0.3862430E+00 -0.4953443E-03 0.2383621E-02 etc 10.0 ... So I wrote the program included below and it only prints the last line of the file. TimestepPE 10.0 -3091.80609 I have one question. Do I need to put ts and pe into a list before I print then to screen or I am just missing something. Thanks. You should print the header before the loop, and the contents inside the loop. So: print TimestepPE for line in cols: ts = line[0] #print line[0] pe = line[1] #print line[1] # The next line is indented so it is included in the loop: print %s %s % (ts,pe) You probably will want to set the field width in the print format so the columns all line up, something like this (just guessing on the widths): print %10s %10 % (ts,pe) You might be interested in this recipe which does a very slick job of pretty-printing a table: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662 Kent Ara import string inp = open(fort.44,r) all_file = inp.readlines() inp.close() outp = open(out.txt,w) cols = map(string.split,all_file) ##print cols Data = {} for line in cols: ts = line[0] #print line[0] pe = line[1] #print line[1] print TimestepPE print %s %s % (ts,pe) outp.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing columns of data
At 01:03 PM 2/8/2005, Kooser, Ara S wrote: Content-class: urn:content-classes:message Content-Type: multipart/alternative; boundary=_=_NextPart_001_01C50E19.4E45912A Hello all, I am writing a program to take a data file, divide it up into columns and print the information back with headers. The data files looks like this 0.0 -3093.44908 -3084.59762 387.64329 26.38518 0.3902434E+00 -0.6024320E-04 0.4529416E-05 1.0 -3094.09209 -3084.52987 391.42288 105.55994 0.3889897E+00 -0.2290866E-03 0.4187074E-03 2.0 -3094.59358 -3084.88826 373.64911 173.44885 0.3862430E+00 -0.4953443E-03 0.2383621E-02 etc 10.0 ... So I wrote the program included below and it only prints the last line of the file. Timestep PE 10.0 -3091.80609 I have one question. Do I need to put ts and pe into a list before I print then to screen or I am just missing something. Thanks. Ara import string inp = open(fort.44,r) all_file = inp.readlines() inp.close() outp = open(out.txt,w) cols = map(string.split,all_file) ##print cols Data = ""> for line in cols: ts = line[0] # print line[0] pe = line[1] # print line[1] print Timestep PE print %s %s % (ts,pe) outp.close() Put the print statement in the for loop. for line in cols: ... print %s %s % (ts,pe) Bob Gailer mailto:[EMAIL PROTECTED] 303 442 2625 home 720 938 2625 cell ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing columns of data
So I wrote the program included below and it only prints the last line of the file. I have one question. Do I need to put ts and pe into a list before I print then to screen or I am just missing something. Thanks. You just need to indent your last print statement so it is inside the loop and put the heading print statement before the loop. print TimestepPE for line in cols: ts = line[0] pe = line[1] print %s %s % (ts,pe) You might also like to use stroing formatting to force column widths to be constant: print %20s%20s % (ts,pe) should illustrate...adjust the size to suit. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor