[Tutor] Use of dateutil.relativedata
Hi trying to use dateutil to calculate the number of months between two dates. here is the script import datetime import dateutil x=datetime.date.today() y=x+datetime.timedelta(days=366) z=y-x print x,y,z a=dateutil.relativedelta(x,y) print a and here is the output >>> 2006-11-15 2007-11-16 366 days, 0:00:00 Traceback (most recent call last): File "C:/Projects/completion_dates", line 10, in -toplevel- a=dateutil.relativedelta(x,y) AttributeError: 'module' object has no attribute 'relativedelta' >>> There's problem here that's really basic but just can't see it!!! Thanks Alun Griffiths ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Use of dateutil.relativedata
Sorry, problem solved import datetime import dateutil.relativedelta x=datetime.date.today() y=x+datetime.timedelta(days=366) z=y-x print x,y,z a=dateutil.relativedelta.relativedelta(x,y) print a seems to do the trick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] numpy memory muncher
> I can reproduce the problem on my Linux system, so it is not Mac > specific. Using xrange makes no difference. I believe that in recent Pythons (v2.3 onwards?) xrange is just an alias for range since range was reimplementted to use generators. So the old menory issues with range no longer apply. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sloppy Code ?
"Matt Erasmus" <[EMAIL PROTECTED]> wrote > Yes, that does help, although it doesn't print the FQDN which is > what > I'm really after. > But thanks to you I now know about the socket module It is very rarely necessaary to use popen etc to get basic system information or to perform basic OS commanfs. There are usually direct function/modules that do the same job more efficiently. popen is good for running actual applications but if you find yourself using it for lower level tasks consider a google search for python . In this case 'python hostname' gets me the socket module docs as the first hit... 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] OT: Vim was: free IDE for Python?
>> I've used vim in the past for python and recommend it for ease of >> use and support. > > I have to chuckle when you recommend Vim for ease of use. Me too, and I've been a vi/elvis/viper/vim user for over 20 years(*). vi/vim could never be described as easy to learn, but... ... ease of use can mean ease of use once you have learned it. ie efficient. Now vim passes that test with flying colours. The guys who designed vi (Bill Joy the founder of Sun Microsystems was one of them) took the view that it should be easy for experts not novices since most programmers would rapidly progress beyond novice. One of the great features of vim is that once you grasp its design philosophy it is entirely consistent and you can often guess new commands without looking it up in the help. For those who want a tutorial that teaches the underlying vi philospohy as well as the basic commands I strongly recommend the vilearn package (sometimes called teachvi). It is a bash script so you need a bash shell to install it but GNU or cygwin bash will work on Windows. Its not pretty but its short and it works: http://www.houseofthud.com/vilearn.html (*) And I've been an emacs user for equally long, I like and use both for different things... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] free IDE for Python?
"wesley chun" <[EMAIL PROTECTED]> wrote > Eclipse >http://pydev.sourceforge.net >http://www.eclipse.org/ Has anyone got an idiot's guide to getting Eclipse working with python? I've tried a couple of times but ran out of patience. In fact I haven't really got vanilla Eclipse working for Java yet, it all seems a lot of work for an IDE! NetBeans was so much easier but my friends all laughed at me and said I should be using Eclipse... :-) Alan (the impatient) G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] removing an image from a tkinter label
"Orri Ganel" <[EMAIL PROTECTED]> wrote > In the end, setting lbl["image"] = "" worked Glad it worked. I was just about to suggest creating an image with the "No image" text in it. You could then just display that as the default image... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] removing an image from a tkinter label
Alan Gauld wrote: >"Orri Ganel" <[EMAIL PROTECTED]> wrote > > > >>In the end, setting lbl["image"] = "" worked >> >> > >Glad it worked. I was just about to suggest creating an image >with the "No image" text in it. You could then just display that >as the default image... > >Alan G. > > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > From what I found, it seems that one version of the documentation (perhaps the original Tcl documentation, as I found no mention of it on effbot) actually says to set it equal to an empty string to return to whatever text is in the label (images take precedence over text). I think setting it equal to another string might have the same effect as setting it equal to None - a TclError. Incidentally, if anyone's interested in the working product (I won't call it final for a while yet), let me know and I can give you a link to the code. Orri G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Alternatives to PY2EXE
"Etrade Griffiths" <[EMAIL PROTECTED]> wrote > just finished developing my first app with wxPython and matplotlib > and now > trying to create an EXE file using PY2EXE for distribution. > However, this > is proving to be an extremely frustrating experience and I am making > very > little progress. Are there any "simple" alternatives to PY2EXE for > shipping Python apps to Windows machines? There are a few more sophisticated tools around but py2exe is usually considered the easy option. But are you sure you really need an EXE? The size of a bundled python install, which can be optionally loaded if not alteady there, is not excessive in modern PC software terms and many environments nowadays do not use pure exe's - VB, .NET, Java Smalltalk, etc So why not just ship Python? And if you writre a lot of code installing python will use up less memory in the long term since you won't have a copy of the interpreter hiding inside every app! Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help me with this problem relating to datetime
Hi Folks, I have got a date (as string), time (as string) , number of slots ( integer) and delta ( which is in seconds). I want to create a dictionary which has got date as the key, and the value should be a tuple with two elements (start_time, end_time). I will take start_time and find the end_time using delta. This pair of start and end times have a corresponding date. The date will be used as the key for the dictionary. Once the time crosses midnight, the date will change. Can you help me to implement this functionality? TIA. Best Regards, Asrarahmed -- To HIM you shall return. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help me with this problem relating to datetime
SOrry for that. I was wondering if someoen can give a hint about the implementation. I am not asking for the actual code. Regards, Asrarahmed On 11/16/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote: Asrarahmed Kadri wrote: > Hi Folks, > > > I have got a date (as string), time (as string) , number of slots ( > integer) and delta ( which is in seconds). > I want to create a dictionary which has got date as the key, and the > value should be a tuple with two elements (start_time, end_time). > > I will take start_time and find the end_time using delta. This pair of > start and end times have a corresponding date. The date will be used > as the key for the dictionary. Once the time crosses midnight, the > date will change. > > > Can you help me to implement this functionality? yes. http://catb.org/esr/faqs/smart-questions.html#prune :). -Luke > > TIA. > > Best Regards, > Asrarahmed > > > > -- > To HIM you shall return. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- To HIM you shall return. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help me with this problem relating to datetime
Asrarahmed Kadri wrote: > Hi Folks, > > > I have got a date (as string), time (as string) , number of slots ( > integer) and delta ( which is in seconds). > I want to create a dictionary which has got date as the key, and the > value should be a tuple with two elements (start_time, end_time). > > I will take start_time and find the end_time using delta. This pair of > start and end times have a corresponding date. The date will be used > as the key for the dictionary. Once the time crosses midnight, the > date will change. > > > Can you help me to implement this functionality? yes. http://catb.org/esr/faqs/smart-questions.html#prune :). -Luke > > TIA. > > Best Regards, > Asrarahmed > > > > -- > To HIM you shall return. > > > ___ > 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] numpy memory muncher
Alan Gauld wrote: >> I can reproduce the problem on my Linux system, so it is not Mac >> specific. Using xrange makes no difference. > > I believe that in recent Pythons (v2.3 onwards?) xrange is just > an alias for range since range was reimplementted to use > generators. So the old menory issues with range no longer > apply. No, range() still returns a list, it is not a generator. That change is for Python 3.0. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help me with this problem relating to datetime
On 16/11/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote: > Hi Folks, > > > I have got a date (as string), time (as string) , number of slots ( integer) > and delta ( which is in seconds). > I want to create a dictionary which has got date as the key, and the value > should be a tuple with two elements (start_time, end_time). > > I will take start_time and find the end_time using delta. This pair of start > and end times have a corresponding date. The date will be used as the key > for the dictionary. Once the time crosses midnight, the date will change. Which part are you having trouble with? To convert a string into a Date or Datetime object, use time.strptime(), and then build a Datetime from the resulting time_tuple. (in Python2.5, I think, the datetime module has its own strptime() function, which short-cuts this process) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] SIP-4.4 Install Borked
To All, This is, and isn't, Python related, but thought you may be of some assisstance. Running Mandriva 2006 on a 1.8Mhz Dell GX260. Also: Python 3.4.2, ERIC3 3.8.1, etc. Problem: was going to update to ERIC3 3.9.2 and downloaded SIP-4.4, PyQT, and others. Started installation with SIP, which went well. Found that due to a raft of dependency problems, the new ERIC and PyQT will not install. Oh well, I thought, I'll just upgrade the OS at my convenience or deal with the problem later. Tried to fire up ERIC, got a segmentation fault. The new SIP has also screwed some other apps. Question: I want to remove SIP and revert to old version and can not find documentation that outlines the procedure. Any suggestions? -- J. D. Leach Columbus, Indiana USA Uptime: 19:37:45 up 1 day, 7:52, 1 user, load average: 1.00, 1.28, 1.49 Linux/Open Source Computer using: Mandriva Linux release 2006.0 (Community) for i586 kernel 2.6.12-12mdk ~~ ---Quote of the Day--- Oh, so there you are! ~~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Alternatives to PY2EXE
Because alot of the users here at Intel dont want to admit you can write usable programs in a "scripting" language.. so when they see a .exe they feel comfy... I'm working on pushing "agile language"... I personally think its more appropriate then scripting =D On 11/15/06, Alan Gauld <[EMAIL PROTECTED]> wrote: "Etrade Griffiths" <[EMAIL PROTECTED]> wrote > just finished developing my first app with wxPython and matplotlib > and now > trying to create an EXE file using PY2EXE for distribution. > However, this > is proving to be an extremely frustrating experience and I am making > very > little progress. Are there any "simple" alternatives to PY2EXE for > shipping Python apps to Windows machines? There are a few more sophisticated tools around but py2exe is usually considered the easy option. But are you sure you really need an EXE? The size of a bundled python install, which can be optionally loaded if not alteady there, is not excessive in modern PC software terms and many environments nowadays do not use pure exe's - VB, .NET, Java Smalltalk, etc So why not just ship Python? And if you writre a lot of code installing python will use up less memory in the long term since you won't have a copy of the interpreter hiding inside every app! 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] free IDE for Python?
I tried it back before I tried SPE. I remember it taking several hours and being very bloated. Have you watched the showmedo video? Thats what I used... http://showmedo.com/videos/series?name=PyDevEclipseList If I personally "had" to use something that obnoxious I'd just reinstall ironpython and use Visual Studio for everything since I already have it for C# applications. (Yes I understand it makes .net runtime code and not python code, but I can't justify using that large and resource eating a program to use a language that is supposed to be quick and easy... ) On 11/15/06, Alan Gauld <[EMAIL PROTECTED]> wrote: "wesley chun" <[EMAIL PROTECTED]> wrote > Eclipse >http://pydev.sourceforge.net >http://www.eclipse.org/ Has anyone got an idiot's guide to getting Eclipse working with python? I've tried a couple of times but ran out of patience. In fact I haven't really got vanilla Eclipse working for Java yet, it all seems a lot of work for an IDE! NetBeans was so much easier but my friends all laughed at me and said I should be using Eclipse... :-) Alan (the impatient) 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] free IDE for Python?
BTW... that also counts as my vouce for using SPE =D On 11/15/06, Chris Hengge <[EMAIL PROTECTED]> wrote: I tried it back before I tried SPE. I remember it taking several hours and being very bloated. Have you watched the showmedo video? Thats what I used... http://showmedo.com/videos/series?name=PyDevEclipseList If I personally "had" to use something that obnoxious I'd just reinstall ironpython and use Visual Studio for everything since I already have it for C# applications. (Yes I understand it makes .net runtime code and not python code, but I can't justify using that large and resource eating a program to use a language that is supposed to be quick and easy... ) On 11/15/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > > "wesley chun" <[EMAIL PROTECTED]> wrote > > Eclipse > >http://pydev.sourceforge.net > > http://www.eclipse.org/ > > Has anyone got an idiot's guide to getting Eclipse working > with python? > > I've tried a couple of times but ran out of patience. In fact I > haven't really got vanilla Eclipse working for Java yet, it all > seems a lot of work for an IDE! NetBeans was so much > easier but my friends all laughed at me and said I should > be using Eclipse... :-) > > Alan (the impatient) 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] SIP-4.4 Install Borked
No need to answer now. I had to resort to the ole' tried-and-true method of aggressive search and destroy. After savagely excising all remnants of sip-4.4, I was able to reload the previous version and get everything back up. Sorry to have troubled you all. On Wednesday 15 November 2006 07:46 pm, J. D. Leach wrote: > To All, > > This is, and isn't, Python related, but thought you may be of some > assisstance. Running Mandriva 2006 on a 1.8Mhz Dell GX260. Also: Python > 3.4.2, ERIC3 3.8.1, etc. > Problem: was going to update to ERIC3 3.9.2 and downloaded SIP-4.4, PyQT, > and others. Started installation with SIP, which went well. Found that due > to a raft of dependency problems, the new ERIC and PyQT will not install. > Oh well, I thought, I'll just upgrade the OS at my convenience or deal with > the problem later. Tried to fire up ERIC, got a segmentation fault. The new > SIP has also screwed some other apps. > Question: I want to remove SIP and revert to old version and can not find > documentation that outlines the procedure. Any suggestions? -- J. D. Leach Columbus, Indiana USA Uptime: 20:46:20 up 1 day, 9:01, 1 user, load average: 1.06, 1.92, 1.85 Linux/Open Source Computer using: Mandriva Linux release 2006.0 (Community) for i586 kernel 2.6.12-12mdk ~~ ---Quote of the Day--- The savior becomes the victim. ~~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Alternatives to PY2EXE
Just want to add to that... As of the day before yesturday I've been using pyInstaller rather then py2exe(which I've used the last few months) I've found some bug that I can't figure out and dont really care to put effort into fixing.. When I run a py.exe using py2exe from the start menu and the user enters any input.. program crashes without errors. When I run a py.exe directly from the command line, it runs flawless. When I run the script from either the start menu or the command line, it runs flawless. I appreciate pyInstaller giving a little more interesting icon to my .exe also... but thats just being picky and lazy. On 11/15/06, Chris Hengge <[EMAIL PROTECTED]> wrote: Because alot of the users here at Intel dont want to admit you can write usable programs in a "scripting" language.. so when they see a .exe they feel comfy... I'm working on pushing "agile language"... I personally think its more appropriate then scripting =D On 11/15/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > > "Etrade Griffiths" <[EMAIL PROTECTED]> wrote > > just finished developing my first app with wxPython and matplotlib > > and now > > trying to create an EXE file using PY2EXE for distribution. > > However, this > > is proving to be an extremely frustrating experience and I am making > > very > > little progress. Are there any "simple" alternatives to PY2EXE for > > shipping Python apps to Windows machines? > > There are a few more sophisticated tools around but py2exe is > usually considered the easy option. > > But are you sure you really need an EXE? > The size of a bundled python install, which can be optionally > loaded if not alteady there, is not excessive in modern PC > software terms and many environments nowadays do not > use pure exe's - VB, .NET, Java Smalltalk, etc > > So why not just ship Python? And if you writre a lot of code > installing > python will use up less memory in the long term since you won't > have a copy of the interpreter hiding inside every app! > > 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
[Tutor] exception problems in socket programming
Hi, I'm trying to do some simple network programming in Python, but am stuck with exception problems. Here's the relevant code snippet: self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.s.connect((something.com, 5000)) except socket.error, (value, message): if self.s: self.s.close() print "Could not open socket: " + message sys.exit(1) I was testing for a timeout exception (which is 60 seconds by default), but after the timeout I get the following error: File "./client.py", line 54, in connect except socket.error, (value, message): ValueError: need more than 1 value to unpack I googled and found something on ValueError, but I couldn't see how it applied here. I'd appreciate any help. Thanks, Vinay ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exception problems in socket programming
I ran this code based on yours: import socket, sys s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(('something.com', 5000)) except socket.error, (value, message): if s: s.close() print "Could not open socket: " + message raw_input("\nPress any key") And I got this result: Could not open socket: getaddrinfo failed Press any key Do you need to put quotes around something.com like I did? On 11/15/06, Vinay Reddy <[EMAIL PROTECTED]> wrote: Hi, I'm trying to do some simple network programming in Python, but am stuck with exception problems. Here's the relevant code snippet: self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.s.connect((something.com, 5000)) except socket.error, (value, message): if self.s: self.s.close() print "Could not open socket: " + message sys.exit(1) I was testing for a timeout exception (which is 60 seconds by default), but after the timeout I get the following error: File "./client.py", line 54, in connect except socket.error, (value, message): ValueError: need more than 1 value to unpack I googled and found something on ValueError, but I couldn't see how it applied here. I'd appreciate any help. Thanks, Vinay ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor