Re: [Tutor] ftplib.storbinary and using a progress bar
On Sat, 6 Sep 2008, johnf wrote: > I'm currently using ftplib.storbinary() to upload a file to a FTP server. > However, I would like to inform the user of the progress being made during > the file transfer (it could be a very long transfer). But > ftplib.storbinary() has no callback like retrbinary() so does anyone have a > thought on how I can update my user on the progress of the transfer. Callbacks are being added in 2.6, and are in the 2.6 source now. You can download the current version of ftplib at http://svn.python.org/view/python/trunk/Lib/ftplib.py?rev=63788&view=log When I do something along these lines, I save it (usually under the local directory of the python program that uses it) under a modified name, i.e. "ftplib26.py" or "myftplib.py"; then import with: import ftplib26 as ftplib ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] ftplib.storbinary and using a progress bar
Hi, I'm currently using ftplib.storbinary() to upload a file to a FTP server. However, I would like to inform the user of the progress being made during the file transfer (it could be a very long transfer). But ftplib.storbinary() has no callback like retrbinary() so does anyone have a thought on how I can update my user on the progress of the transfer. BTW I have to use a binary transfer because the file being transfer is not text. -- John Fabiani ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems starting python
On Fri, Sep 5, 2008 at 6:28 AM, Linus Lindström <[EMAIL PROTECTED]> wrote: > Hello. When i first installed python from the cd i bought it seemed to work > perfectly... But then when i cancel the program and try to start it again I > get the message: "IDLE's subprocess didn't make connection. Either IDLE > can't start a subprocess or a personal firewall software is blocking the > connection.", and the problem still stands... I've tried to completely shut > down my firewall but without success... Please help me! A little googling reveals a possible fix below; I'm not sure I get it though. If this fails, you can try running idle with the "-n" flag, which avoids running a subprocess. --- from http://www.cs.sfu.ca/CC/CSILPC/kip.html#s2-20 IDLE (Python GUI) won't start! What should I do? Sometimes when IDLE starts, it prompts the following error message: Subprocess Startup Error: IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection. Here is the workaround (a fix is under research): * launch Windows Explorer * find (or create) a file with .py extension * right click this file, select "Edit with IDLE" Now, the IDLE (Python GUI) should start. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with using methods in a base class
"Roy Khristopher Bayot" <[EMAIL PROTECTED]> wrote ... def generateClockPulse(self): ... parallel.Parallel.setSelect(0) ... parallel.Parallel.setSelect(1) ... a = LightsHandle() a.setD(0xF0) Traceback (most recent call last): File "", line 1, in File "", line 5, in setD TypeError: unbound method setData() must be called with Parallel instance as first argument (got int instance instead) The error merssage gives the clue. Sonce you are calling a method on a classs not an object you need to pass in the instance reference explicitly. Its exactly as in calling the base constructor in __init__ class C(P): def __init__(self): P.__init__(self)# need to pass self here (Some notes: I changed setData() to setD() so that there wont be a confusion. Method setData() is from the base class Parallel. Although I think setData() could be overriden.) Thats not necessary, each class creates its owen namespace. What have I been doing wrong? Why does it say that I need a Parallel instance? Because the class needs to know where to find the instance variables. Since you are calling the class directly, not via an instance you have to pass self explicitly. Remember that in class C: def m(self, x): print x c = C(42) Then c.m() is the same as C.m(c,42). self takes on the value of the instance in the first case but in the second you have to pass it directly. When you are inside a methiod you always use the second form so you always need to pass self. 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] Sending email as html
"Tim Johnson" <[EMAIL PROTECTED]> wrote since PDF files are not very hard to edit with a simple text editor. (Never have really.) Looks like I could make up a PDF template and then put substitutions You could although they are not pure text files so you may need to use binary mode to edit the file I think. There is an interersting looking link here: http://www.python.org/workshops/2002-02/papers/17/index.htm HTH, Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with using methods in a base class
On Sat, Sep 6, 2008 at 12:04 PM, Roy Khristopher Bayot <[EMAIL PROTECTED]> wrote: > Hi. I am having some difficulty using methods from a base class. > > I have 2 classes. The first one is Parallel which is inside the module > parallel. The methods useful to me from this class are setDataStrobe(), > setAutoFeed(), setInitOut(), setSelect(), and setData(). > > The second one is derived from the first. I called it LightsHandle. The code > and traceback is written below: > import parallel class LightsHandle(parallel.Parallel): > ... def __init__(self): > ... pass > ... def setData(self, data): > ... Parallel.setData(data) > ... def setLatch(self, latch): > ... Parallel.setDataStrobe(int(latch[0])) > ... Parallel.setAutoFeed(int(latch[1])) > ... Parallel.setInitOut(int(latch[2])) > ... def generateClockPulse(self): > ... Parallel.setSelect(0) > ... Parallel.setSelect(1) > ... a = LightsHandle() a.setData(0xF0) > Traceback (most recent call last): > File "", line 1, in > File "", line 5, in setData > NameError: global name 'Parallel' is not defined This error is because you did not import Parallel, you imported parallel. You have to use the full name parallel.Parallel as you figured out. You could also use from parallel import Parallel and then just refer to Parallel. > So I tried another one. And the code and traceback is written below. > import parallel class LightsHandle(parallel.Parallel): > ... def __init__(self): > ... pass > ... def setD(self, data): > ... parallel.Parallel.setData(data) > ... def setLatch(self, latch): > ... parallel.Parallel.setDataStrobe(int(latch[0])) > ... parallel.Parallel.setAutoFeed(int(latch[1])) > ... parallel.Parallel.setInitOut(int(latch[2])) > ... def generateClockPulse(self): > ... parallel.Parallel.setSelect(0) > ... parallel.Parallel.setSelect(1) > ... a = LightsHandle() a.setD(0xF0) > Traceback (most recent call last): > File "", line 1, in > File "", line 5, in setD > TypeError: unbound method setData() must be called with Parallel instance as > first argument (got int instance instead) > > (Some notes: I changed setData() to setD() so that there wont be a > confusion. Method setData() is from the base class Parallel. Although I > think setData() could be overriden.) > > What have I been doing wrong? Why does it say that I need a Parallel > instance? > > According to > http://www.python.org/doc/2.5/tut/node11.html#SECTION001134 > > "There is a simple way to call the base class method directly: just call > "BaseClassName.methodname(self, arguments)". This is occasionally useful to > clients as well. (Note that this only works if the base class is defined or > imported directly in the global scope.) " This quote has the answer to your question. When you call the base class method, you have to explicitly provide the self parameter, e.g. parallel.Parallel.setData(self, data) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Need help with using methods in a base class
Hi. I am having some difficulty using methods from a base class. I have 2 classes. The first one is Parallel which is inside the module parallel. The methods useful to me from this class are setDataStrobe(), setAutoFeed(), setInitOut(), setSelect(), and setData(). The second one is derived from the first. I called it LightsHandle. The code and traceback is written below: >>> import parallel >>> class LightsHandle(parallel.Parallel): ... def __init__(self): ... pass ... def setData(self, data): ... Parallel.setData(data) ... def setLatch(self, latch): ... Parallel.setDataStrobe(int(latch[0])) ... Parallel.setAutoFeed(int(latch[1])) ... Parallel.setInitOut(int(latch[2])) ... def generateClockPulse(self): ... Parallel.setSelect(0) ... Parallel.setSelect(1) ... >>> a = LightsHandle() >>> a.setData(0xF0) Traceback (most recent call last): File "", line 1, in File "", line 5, in setData NameError: global name 'Parallel' is not defined So I tried another one. And the code and traceback is written below. >>> import parallel >>> class LightsHandle(parallel.Parallel): ... def __init__(self): ... pass ... def setD(self, data): ... parallel.Parallel.setData(data) ... def setLatch(self, latch): ... parallel.Parallel.setDataStrobe(int(latch[0])) ... parallel.Parallel.setAutoFeed(int(latch[1])) ... parallel.Parallel.setInitOut(int(latch[2])) ... def generateClockPulse(self): ... parallel.Parallel.setSelect(0) ... parallel.Parallel.setSelect(1) ... >>> a = LightsHandle() >>> a.setD(0xF0) Traceback (most recent call last): File "", line 1, in File "", line 5, in setD TypeError: unbound method setData() must be called with Parallel instance as first argument (got int instance instead) (Some notes: I changed setData() to setD() so that there wont be a confusion. Method setData() is from the base class Parallel. Although I think setData() could be overriden.) What have I been doing wrong? Why does it say that I need a Parallel instance? According to http://www.python.org/doc/2.5/tut/node11.html#SECTION001134 "There is a simple way to call the base class method directly: just call "BaseClassName.methodname(self, arguments)". This is occasionally useful to clients as well. (Note that this only works if the base class is defined or imported directly in the global scope.) " Do I have a problem in scope? How can I resolve it? Thank you and have a nice day. ^_^ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sending email as html
On Saturday 06 September 2008, Glen Wheeler wrote: > From: "Alan Gauld" <[EMAIL PROTECTED]> > > > "Lie Ryan" <[EMAIL PROTECTED]> wrote > > > >>> programs which can edit PDFs which has somewhat destroyed > >>> their value as a read-only document format for contracts, invoices > >>> etc... > >> > >> If you have used tried using any PDF editor for more than correcting > >> typos, you'd still consider it as a read-only document. > > > > True. but for contracts or invoices just changing a 1 to a 7 or vice > > versa can make a big difference to the money owed! And very > > little difference to the layout. > > Well if it's just a matter of changing one digit this isn't so hard, > since PDF files are not very hard to edit with a simple text editor. > (Never have really.) Looks like I could make up a PDF template and then put substitutions into it. thanks tim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sending email as html
"Glen Wheeler" <[EMAIL PROTECTED]> wrote If you have used tried using any PDF editor for more than correcting typos, you'd still consider it as a read-only document. True. but for contracts or invoices just changing a 1 to a 7 or vice versa can make a big difference to the money owed! And very little difference to the layout. Well if it's just a matter of changing one digit this isn't so hard, since PDF files are not very hard to edit with a simple text editor. (Never have That's true if you understand the PDF format but its non trivial and way beyond most computer users. But PDF has never been absolutely secure, just better than Word documents or plain text. If you really want to check that the doc has not been altered you need to use digital signing or similar. PDF is just a discouragement. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Replace sequence in list - looking for direction
"peter hodgson" <[EMAIL PROTECTED]> wrote for key in b: keylist = key.split(',') if keylist < a: i = a.index(keylist[0]) print a[:i] + [b[key]] + a[i+len(keylist):] now, i get it, mostly; but keylist being shorter than the list "a" keylist < a True This is not testing the length it is testing the contents. a = ['a','c','e'] b = ['b','d','f'] a True b False It sees that 'a' < 'b' so returns True for a c = ['a','b','c'] c True Here the a's are equal so it checks the second element and finds b < c so c Finally for unequal length strings d = ['a','c'] d True d False So d winds over a since the third element not existing is taken to be lower valued than it existing. But the character values in d Does that make sense? So in the original program for key in b: keylist = key.split(',') if keylist < a: i = a.index(keylist[0]) print a[:i] + [b[key]] + a[i+len(keylist):] It is checking that it will find a valid index in the i assignment. Having said that I'm not sure the check is fully effective since I have a feeling it may fail for duplicated instances of the first letter But to answer your question the list comparison is more complex than just length. And finally the a{:i] part is to cover the case where the index i is greater than 0. So we retain the initial values up to the matching key. 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] how do you make this a better code?
Hi. I tried it. It worked. Thank you. On Fri, Sep 5, 2008 at 9:42 AM, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Thu, Sep 4, 2008 at 9:00 PM, Roy Khristopher Bayot > <[EMAIL PROTECTED]> wrote: > > > class CamHandle(object): > > def __init__(self): > > import os > > w = os.system('gphoto2 --auto-detect > CamHandleLog.txt') > > test = os.system('gphoto2 --capture-image >> CamHandleLog.txt') > > > > def captureImage(self): > > import os > > x = os.system('gphoto2 --capture-image >> CamHandleLog.txt') > > > > Now when I import the file to the interpreter and instantiate the class, > it > > works. Each function works. I havent done any error handling or exception > > handling yet but it works for now. However, I am bothered with the import > > statements in each function. > > The usual method is to put the import statement at the beginning of > the module. Then the imported module has global (module) scope rather > than function scope. > > Kent > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Support for datetime module
On Sat, Sep 6, 2008 at 2:42 AM, Johan Geldenhuys <[EMAIL PROTECTED]> wrote: > Hi all, > > I have want to use the datetime module on a system with ver 2.2.3 installed. > I know it's very old, but that's what I have to deal with and can't upgrade. > So please don't suggest that. > > As you know datetime was available from version 2.3. > > > > I want to know where can I get the datetime module so that I can include it > in my package that I use on my device? datetime is implemented in C so getting the version from 2.3 to work on 2.2 might be difficult. Apparently the version in the std lib is derived from a Python version that was part of Zope, this might be helpful if you can find the source it refers to: http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Support for datetime module
Hi all, I have want to use the datetime module on a system with ver 2.2.3 installed. I know it's very old, but that's what I have to deal with and can't upgrade. So please don't suggest that. As you know datetime was available from version 2.3. I want to know where can I get the datetime module so that I can include it in my package that I use on my device? I looked on the Internet but can't find it. So if anybody can give me a link to get the module, I'll be very thankful, Regards Johan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Replace sequence in list - looking for direction
greetings, fellow ventriloquists; the exchanges on this list are great tutorials; sometimes i don't quite get the finer points; like here: On Mon, Jun 16, 2008 at 10:41 AM, GTXY20 <[EMAIL PROTECTED]> wrote: > Let's say I have a list like the following: > > a = ['a1','a2','a3','a4','a5','a6'] > > and then I have dictionary like the following: > > b = {'a1,a2,a3':'super'} > > I need some direction and thoughts on how I might seach the list for the > string (the key in dict b) sequence in list a and replace the occurance with > the value from dict b. At the end I would like to have list a represented > as: > > a = ['super', 'a4', 'a5', 'a6'] the solution: From: Tiago Saboga <[EMAIL PROTECTED]> The following works for your example. I assume the values in the a list are unique. for key in b: keylist = key.split(',') if keylist < a: i = a.index(keylist[0]) print a[:i] + [b[key]] + a[i+len(keylist):] - but this works, too; >>> a = ['a1','a2','a3','a4','a5','a6'] >>> b = {'a1,a2,a3':'super'} >>> for key in b: ... keylist = key.split(',') ... i = a.index(keylist[0]) ... print [b[key]] + a[i+len(keylist):] ... ['super', 'a4', 'a5', 'a6'] --- now, i get it, mostly; but keylist being shorter than the list "a" >>> keylist < a True doesn't seem relevant, unless the 'for' statement were to go on and on; and if a[:i] = zilch: >>> for key in b: ... keylist = key.split(',') ... if keylist < a: # DOES THIS MEAN LENGTH? ... i = a.index(keylist[0]) # a[index of first item in the key == 0]; ... print a[:i] # a[:0] == pre-first item == None; ... [] then why bother with that part? - finally, how might the code handle a dictionary with more than one item? since i figured the line if keylist < a: might be part of some kind of iteration, say, until all of the items in "a" had been replaced by dictionary values, this is as far as i got: >>> a = ['a','b','c','d','e','f'] >>> b = {'a,b':'firstval', 'c,d':'secondval'} >>> for key in b: ... keylist = key.split(',') ... if keylist < a: ... i = a.index(keylist[0]) ... print a[:i] + [b[key]] + a[i+len(keylist):] ... ['firstval', 'c', 'd', 'e', 'f'] but 'secondval' did not replace 'c' and 'd' in "a"; what am i missing? thanks, imputerate ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sending email as html
From: "Alan Gauld" <[EMAIL PROTECTED]> "Lie Ryan" <[EMAIL PROTECTED]> wrote programs which can edit PDFs which has somewhat destroyed their value as a read-only document format for contracts, invoices etc... If you have used tried using any PDF editor for more than correcting typos, you'd still consider it as a read-only document. True. but for contracts or invoices just changing a 1 to a 7 or vice versa can make a big difference to the money owed! And very little difference to the layout. Well if it's just a matter of changing one digit this isn't so hard, since PDF files are not very hard to edit with a simple text editor. (Never have really.) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sending email as html
"Lie Ryan" <[EMAIL PROTECTED]> wrote programs which can edit PDFs which has somewhat destroyed their value as a read-only document format for contracts, invoices etc... If you have used tried using any PDF editor for more than correcting typos, you'd still consider it as a read-only document. True. but for contracts or invoices just changing a 1 to a 7 or vice versa can make a big difference to the money owed! And very little difference to the layout. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor