[Tutor] how to setup gnu.py
hi! i don't know if this is the proper forum but i'll ask anyway... how am i going to setup gnu.py(or gnuplot.py) gnuplot with python??? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read from a txt file
am getting desperate on this, please help me, I just can't figure out how to read those tabs please help me! On Tue, 29 Mar 2005 22:16:11 -0800, jrlen balane [EMAIL PROTECTED] wrote: I need the string representation of the data read so that i can put it on a wxGrid while i am goin to need the integer representation of the data so that i can plot it. anybody, please help!!! On Tue, 29 Mar 2005 20:56:16 -0800, jrlen balane [EMAIL PROTECTED] wrote: how should i modify this data reader: (assumes that there is only one entry per line followed by '\n') data_file = open(os.path.normpath(self.TextFile.GetValue()), 'r') data = data_file.readlines() self.irradianceStrings = map(str, data) self.irradianceIntegers = map(int, data) self.IrradianceExecute.SetValue(''.join(self.irradianceStrings)) so that i can read the text file created by this: self.filename = %s\%s.txt %(os.path.normpath(self.SaveFolder.GetValue()),time.strftime(%Y%m%d%H%M)) self.table_file = open(self.filename,a) self.table_file.write('%f\t'%self.temp11) self.table_file.write('%f\t'%self.temp22) self.table_file.write('%f\t'%self.pyra11) self.table_file.write('%f\t'%self.pyra22) self.table_file.write('%f\t'%self.voltage11) self.table_file.write('%f\t'%self.current11) self.table_file.write('\n') self.table_file.close() On Tue, 15 Mar 2005 17:05:46 +1300, Liam Clarke [EMAIL PROTECTED] wrote: Whoops, golden rule - Never post untested code Sorry. On Mon, 14 Mar 2005 21:05:44 -0500, Kent Johnson [EMAIL PROTECTED] wrote: jrlen balane wrote: ok, i've done what sir Kent just said, my fault... but an error still occurs: Traceback (most recent call last): File C:\Python23\practices\opentxtprintlngnew.py, line 18, in -toplevel- print process(data) File C:\Python23\practices\opentxtprintlngnew.py, line 10, in process tempLine = int(line) ValueError: invalid literal for int(): abc isn't this the job of : except TypeError: print Non numeric character in line, line continue #Breaks, and starts with next line Yes, only it should be ValueError instead of TypeError. You can check this interactively: int('foo') Traceback (most recent call last): File stdin, line 1, in ? ValueError: invalid literal for int(): foo Kent ___ 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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] max. range of list
how many is the maximum member can a list have??? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max. range of list
thanks for the information... On Fri, 25 Mar 2005 10:26:00 -0500, Kent Johnson [EMAIL PROTECTED] wrote: jrlen balane wrote: how many is the maximum member can a list have??? According to this thread http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/2ddae82bb2c1b871/e00b7903bc887a73 the number of element in a list is stored in an int, so most likely the hard limit is 2**31-1. The practical limit is the available memory. Kent ___ 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] creating a tab delimited filename
that is exactly what i am looking for, but how would i add this to my filename??? should i use this: output_file = open(os.path.join(self.Save_Session.GetValue(), time.strftime('%Y%m%d%H%M')), 'w') the self.Save_Session.GetValue() is generated by a dirdialog On Tue, 15 Mar 2005 09:41:35 -0600, C Smith [EMAIL PROTECTED] wrote: On Tuesday, Mar 15, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: how am i going to change the filename automaticaly? for example: #every 5 minutes, i am going to create a file based on the data above for i in range(100) output_file = file('c:/output' +.join(i) +'.txt', 'w') #guess this won't work output_file.writelines(lines) output_file.close() When faced with this problem, one of the tings that I liked to do was use a date stamp for the files. The time module has a function called strftime which allows you to use a template to create a string from the current time. (See the documentation of python module 'time' for more details.) e.g. ### import time time.strftime('%Y%m%d%H%M') '200503150934' ### This string can be added to your 'c:/output' rather than a generic number like i. Just to be safe you might want to check that the file doesn't already exist. The nice thing is that there should be few files that have this number added to them so the loop to get a valid name is going to succeed quickly. /c ___ 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] how to read from a txt file
say i have the code that reads decimal value from a text file: import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: data_points.append(int(line)) return data_points print process(data) what if, on the text file, a user has encoded values other than decimal, how would i add a code that would act like an Exception, or would tell the user that there is an invalid entry in the text file, like a letter or other character other than number ? On Thu, 17 Feb 2005 01:44:19 -0800 (PST), Danny Yoo [EMAIL PROTECTED] wrote: Traceback (most recent call last): File C:\Python23\practices\opentxt, line 12, in -toplevel- process(data) File C:\Python23\practices\opentxt, line 6, in process data_points.append(int(line)) ValueError: invalid literal for int(): Hi Brian, Ah, think about empty lines. Let's look at the error message again: ValueError: invalid literal for int(): ^^^ There's nothing visible there after the colon, and that's our hint. Notice what happens when we pass int() some wacky strings: ### int(foobar) Traceback (most recent call last): File stdin, line 1, in ? ValueError: invalid literal for int(): foobar ### So whatever is being passed to int() should show up in the error message. This is exactly why getting literal error messages is so wonderful. *grin* Since we don't see anything here: File C:\Python23\practices\opentxt, line 12, in -toplevel- process(data) File C:\Python23\practices\opentxt, line 6, in process data_points.append(int(line)) ValueError: invalid literal for int(): my best guess is that there's an empty line in the file, since we get the same kind of error if we do this: ### int() Traceback (most recent call last): File stdin, line 1, in ? ValueError: invalid literal for int(): ### Best of wishes to you! ___ 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] how to read from a txt file
this is what i get after running this on IDLE: import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: try: tempLine = int(line) except TypeError: print Non numeric character in line, line continue #Breaks, and starts with next line data_points.append(tempLine) return data_points print process(data) = [1000] == but this is what i have written on the text file: 1000 890 900 abc 500 650 850 1200 1100 On Tue, 15 Mar 2005 12:53:26 +1300, Liam Clarke [EMAIL PROTECTED] wrote: Oops, and I meant try: tempLine = int(line) Silly indent error. On Tue, 15 Mar 2005 12:52:49 +1300, Liam Clarke [EMAIL PROTECTED] wrote: Well, a string 12345 when called through int() will come back as 12345. But, a string foo, called through int(), will raise a TypeError. So import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: data_points.append(int(line)) return data_points print process(data) You could do this def process(list_of_lines): data_points=[] for line in list_of_lines: try: tempLine = int(line) except TypeError: print Non numeric character in line, line continue #Breaks, and starts with next line data_points.append(tempLine) That's one way, but there's probably a better way. Regards, Liam Clarke -- '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. -- '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
[Tutor] creating a tab delimited filename
what does a tab delimited filename mean? how am i going to make this? also how does it differs from space delimited, csv, and others? can't really find an article that could put me in the right direction so i posted here. thanks in advance. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] creating a tab delimited filename
so for example, i am creating a text file with file.write() how am i going to make the file a tab-delimited file??? any parameters needed??? On Sun, 13 Mar 2005 15:59:46 -0800 (PST), Danny Yoo [EMAIL PROTECTED] wrote: On Sun, 13 Mar 2005, jrlen balane wrote: what does a tab delimited filename mean? how am i going to make this? also how does it differs from space delimited, csv, and others? Hello, As Kent mentioned, you probably mean tab delimited file, which means a file whose lines are split up into columns. Each column is separated by a tab, which, in theory, should make it easy to parse. The main difference between a tab-delimited file and the others you mention is the delimiter, the separator that's chosen to break columns apart. By the way, you might be interested in: http://www.faqs.org/docs/artu/ch05s02.html#id2901882 which talks a lot more about file formats in Unix and their relative strengths and weaknesses. Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] creating a tab delimited filename
specifically, I want to write an array in to a text file, how am i going to make the file a tab-delimited file??? On Mon, 14 Mar 2005 08:37:35 +0800, jrlen balane [EMAIL PROTECTED] wrote: so for example, i am creating a text file with file.write() how am i going to make the file a tab-delimited file??? any parameters needed??? On Sun, 13 Mar 2005 15:59:46 -0800 (PST), Danny Yoo [EMAIL PROTECTED] wrote: On Sun, 13 Mar 2005, jrlen balane wrote: what does a tab delimited filename mean? how am i going to make this? also how does it differs from space delimited, csv, and others? Hello, As Kent mentioned, you probably mean tab delimited file, which means a file whose lines are split up into columns. Each column is separated by a tab, which, in theory, should make it easy to parse. The main difference between a tab-delimited file and the others you mention is the delimiter, the separator that's chosen to break columns apart. By the way, you might be interested in: http://www.faqs.org/docs/artu/ch05s02.html#id2901882 which talks a lot more about file formats in Unix and their relative strengths and weaknesses. Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] What does this mean
what does (*args, **kwargs) mean??? i'm sort of a bit confused... thanks. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] what is wrong with this?
this code is for a MDIChildFrame, It has a MDIParentFrame and when I run the MDIPrentFrame, there seems to be no problem, but when I attempt to edit the MDIChildFrame using the designer mode in BOA (i'm using BOA by the way), an error occurs that says: TypeError: wxGrid_CreateGrid() takes at least 3 arguments (2 given) please help. here is the code: from wxPython.wx import * from wxPython.grid import * from wxPython.lib.mixins.grid import wxGridAutoEditMixin def create(parent): return wxMDIChildFrame1(parent) [wxID_WXMDICHILDFRAME1, wxID_WXMDICHILDFRAME1GRID1, ] = map(lambda _init_ctrls: wxNewId(), range(2)) class wxMDIChildFrame1(wxMDIChildFrame): def _init_ctrls(self, prnt): # generated method, don't edit wxMDIChildFrame.__init__(self, id=wxID_WXMDICHILDFRAME1, name='WXMDICHILDFRAME1', parent=prnt, pos=wxPoint(70, 147), size=wxSize(748, 331), style=wxDEFAULT_FRAME_STYLE, title='Table') self.SetClientSize(wxSize(740, 297)) self.grid1 = wxGrid(id=wxID_WXMDICHILDFRAME1GRID1, name='grid1', parent=self, pos=wxPoint(0, 0), size=wxSize(740, 297), style=0) self.grid1.CreateGrid(100,6) self.grid1.SetColLabelValue(0, Time) self.grid1.SetColLabelValue(1, Irradiance) self.grid1.SetColLabelValue(2, Module Temperature) self.grid1.SetColLabelValue(3, Ambient Temperature) self.grid1.SetColLabelValue(4, Voltage) self.grid1.SetColLabelValue(5, Current) self.grid1.SetColSize(2, 125) self.grid1.SetColSize(3, 127) self.grid1.SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_BOTTOM) def __init__(self, parent): self._init_ctrls(parent) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] what is wrong with this?
how would i find the stack trace? by the way, this is what the log says: 11:53:16: TypeError: wxGrid_CreateGrid() takes at least 3 arguments (2 given)Traceback(most recent call last): 11:53:16: TypeError: wxGrid_CreateGrid() takes at least 3 arguments (2 given) File C:\PYTHON23\Lib\site-packages\wxPython\tools\boa\Models\wxPythonControllers.py, line 80, in OnDesigner 11:53:16: self.showDesigner() 11:53:16: File C:\PYTHON23\Lib\site-packages\wxPython\tools\boa\Models\wxPythonControllers.py, line 145, in showDesigner 11:53:16: designer.refreshCtrl() 11:53:16: File C:\PYTHON23\Lib\site-packages\wxPython\tools\boa\Views\Designer.py,line 379, in refreshCtrl 11:53:16: self.initObjectsAndCompanions(objCol.creators[1:], objCol, deps, depLnks) 11:53:16: File C:\PYTHON23\Lib\site-packages\wxPython\tools\boa\Views\InspectableViews.py, line 140, in initObjectsAndCompanions 11:53:16: dependents, depLinks) 11:53:16: File C:\PYTHON23\Lib\site-packages\wxPython\tools\boa\Views\InspectableViews.py, line 216, in initObjProps 11:53:16: getattr(ctrl, prop.prop_setter)(value) 11:53:16: File C:\PYTHON23\lib\site-packages\wxPython\grid.py, line 973, in CreateGrid 11:53:16: val = gridc.wxGrid_CreateGrid(self, *_args, **_kwargs) 11:53:16: TypeError: wxGrid_CreateGrid() takes at least 3 arguments (2 given) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to separate hexadecimal
i have a 4 digit hex number (2 bytes) and i want to separate it into 2 digit hex (1 byte each) meaning i want to get the upper byte and the lower byte since i am going to add this two. how am i going to do this? should i treat it just like a normal string? please help, thanks. ex. hexa = '0x87BE # what i want to do is: a = 0x87, b = 0xBE# so that i could do this: c = a + b#which should be equal to 0x145 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to plot a graph
i'm going to use now the matplotlib in plotting a graph. i'm currently using python 2.3(enthought edition) on win 2000/xp. i'm using boa constructor on the GUI part. i am using an MDIParentFrame. one of the child frame will be used for the table part. then another child frame will be used to show the graph, how am i going to do this? will i just import the child frame containing the tables and then i'll be able to just get the data from the table and use it to plot a graph? how am i going to assign to a variable each input to the table? can you please show me a sample code to do this? i'm a little lost since i'm a bit new to python. also, how am i going to assign to a variable anything that a user inputs to a wxTxtCtrl? any help would greatly be appreciated. thanks and more power ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor