From: Jeff E. <jem...@fr...> - 2006-08-20 18:14:47
|
strftime http://docs.python.org/lib/module-time.html WordWeaver wrote: > Hello Everyone, > > I am a brand new Python programmer with barely a month of > experience under my belt. > > > Here are my specs: > > Mac OSX Panther 10.3.9 > Jython 2.1 implementation > Hermes BBS python module installed > > > And now the problem... > > Right now I am having a small problem figuring out how to > properly format the "User Last Log-On" date for the new > external/door that I am writing for our Hermes BBS. > > Initially, I was using the following in my user > initialization function near the top of the code: > > user.data.usrUndrLast = time.localtime() > > "user.data.usrUndrLast" is a user data object that I created > to display the last time that a person used the external. As > you can see, I an setting the value of the object to > "time.localtime()". > > The problem is that the above code gives me a long string like > this: > > (2006, 8, 19, 23, 39, 15, 5, 231, 0) > > Well, that obviously is not what I want or need. I don't > need seconds, or whatever that is that follows after > seconds...And that isn't the format I want either. > > So I scrounged around in the example code for another > external I have here, as well as in the hermes.py, (module > which contains some of the BBS's proprietary functions), the > jython-2.1 folder, (Python implementation I am using with the > BBS), and even in my OSX Python installation, and then also > on the web, looking for a clue regarding how to get it to do > what I want it to do. > > I figured out that adding [:3] like this: > > user.data.usrUndrLast = time.localtime()[:3] > > ...would reduce it to just "(2006, 8, 19)", but that is still > not what I want it to do. The format is wrong. > > I found a lot of interesting stuff inside of "rfc822.py" > concerning date and time formats, but I am still not grasping > quite how to do this. > > Right now, I am getting a TypeError, I guess because > time.localtime only deals with integers, and I am trying to > throw strings at it as well, like this: > > user.data.usrUndrLast = time.localtime('%a, %d %b %Y') > > I was hoping that the above code would produce something like this: > > Sun 20 Aug 2006 > > ...but what I am getting is a TypeError which states: > > "TypeError: localtime(): 1st arg can't be coerced to double" > > Being new to Python/Jython, I don't quite understand it. > > So at this point, I am pretty stumped. In the list of > players, I just want it to show when they were last logged > into the external, preferably in one of the following > formats: > > Sun 20 Aug 2006 > Sun Aug 20 2006 > Aug 20 2006 > 08-20-06 > 08-20-2006 > 08/20/2006 > 08/20/06 > > Once the above code, (user.data.usrUndrLast = time.localtime), > initializes their last log-on date, I am using that date in > a user list by appending the date to the user list like this: > > for u in external.users.values(): > usrList.append({ > 'name': u.data.usrUndrName, > 'levl': u.data.usrUndrLevl, > 'scor': u.data.usrUndrScor, > 'last': u.data.usrUndrLast, # The one we're dealing with > }) > > The above list code queries the external for the values that > it has stored for each user. When it gets to the "last" item > in the list, the external is supposed to send it the value > for "u.data.usrUndrLast", (which it does), which is filled in > with the value of "time.localtime()" Once the list is made, > the "last" code will be displayed in the user list using this > piece of code: > > print Style(fgLtGreen)('%(last)-10s' % markUsr) > > For the record, I do have "import time" at the top of my > code. I looked all over the place for a module called > "time.py", but couldn't find one. So I didn't quite > understand where "time.py" was being imported from. I finally > figured that it must just be a function which is being > imported from one of the jython modules that I was looking > at...although I never found an exact function called "time()" > or "time.localtime(). > > So if anyone can lend me a hand with this, I'd really appreciate > it. I am really working hard, and doing the best I can to learn > Python, (my very first programming language), but I still require > some guidance. > > If anyone here can tell me how to get the results that I want, I > would really appreciate it. > > Thanks so much. > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |