@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21



Comments:

<0> Wolfman2000: but remember we seperated the rank and suits from any values, including names. they only have names in the context of the Deck, so only it can say what their name is. nameOf itself gives out the name.
<1> ajaksu: you would think, but i haven't found a way to do so
<2> ...I think I forgot that.
<0> jerbear: you want the tzinfo parameter
<3> there you go.
<4> jerbear: sorry, time module I meant
<3> if you have a timestamp and you want a datetime, it's datetime.fromtimestamp()
<1> ironfroggy: tzinfo is just a base cl*** in naive datetime objects
<4> jerbear: can you give me a utc string? :)
<0> jerbear: you have to give a datetime object a timezone or its standard time.
<0> Wolfman2000: ok so now you remember
<2> A little.
<2> I am stumped as to how to get this implementation the way you are thinking of though.
<2> I'm stuck on this same tricky spot.
<1> ironfroggy: ok, so let's say i have this... dt = datetime.utcnow()
<1> ironfroggy: how would i add tz info and get localtime?



<0> jerbear: i dunno. ive told you all i know.
<0> Wolfman2000: what has you stuck? how it gets the name?
<2> Yes.
<1> ironfroggy: how can you make a statement like you did above without knowing if it's even possible?
<0> of course its possible.
<0> i dont have to know how to do something exactly to know that its possible.
<0> return [name.title() for (name, attr) in self.__dict__ if attr is item][0]
<1> i have not found a way to do it, and i haven't seen anything to indicate otherwise
<0> that will iterate ever all attributes of the Deck, and the one the matches (that is, the suit or rank you gave it) will be found and its name capitalized and returned.
<0> jerbear: rtfm
<3> holy crap, is this for real?
<3> http://www.python.org/doc/current/lib/datetime-tzinfo.html
<0> help(datetime.tzinfo) tells you exactly what you need
<3> i knew python's builtin time stuff was awful, but that's execrable
<3> actually, it tells you very little about what you need
<3> you have to derive a ****ing subcl*** just to specify a timezone? that's insane
<1> mfen: yeh, i saw that..
<5> "i need to store timestamps in utc and convert them to localtime for display" > There's a function for that.
<1> irontfroggy: ... when i was rtfm...
<1> pythy: what function is that?
<5> calendar's timegm(tuple) :: timegm: Unrelated but handy function to calculate Unix timestamp from GMT.
<5> timegm() (in module calendar): http://doc.python.org/lib/module-calendar.html#l2h-1458
<1> pythy: i'm not dealing with unix timestamps
<6> Im not normally one for the mainstream stuff, but damn RHCP's new album is rockin'
<5> convert them.
<6> Then again, theyre amazing live also :D
<2> ironfroggy: Perhaps we should go for what I'm trying here another time? I don't think we're making good progress this time around.
<0> Wolfman2000: that line i gave you is all you need for the nameOf method
<2> I missed the line.
<0> scrollback, its therer
<4> jerbear: I'd get datetime.now() and datetime.utcnow(), and get a constant to fix from utc
<7> boy, that is nasty
<4> but that's awful too
<4> :D
<2> This? return [name.title() for (name, attr) in self.__dict__ if attr is item][0]
<0> yeah
<2> ...I won't ask right now.
<0> think of it as a compacted for loop
<0> that just looks for the attribute that is the object you p***ed it, and returns the name of that attribute capitolized.
<2> ...an ugly compacted for loop where I don't understand the stuff.
<0> expand it
<2> Well...I still get the hex stuff.
<0> i just didnt want to flood
<7> ironfroggy: self.__dict__.iteritems() ?
<0> joedj: yeah, oops
<0> Wolfman2000: yeah that should be self.__dict__.items()
<2> I appreciate the lack of flooding...but let me see if I can get this in compact.
<5> jerbear: dto = datetime.datetime.utcnow(); t = dto.timetuple()[:6]
<5> >>> time.ctime(calendar.timegm(t)) #==> 'Sun May 28 00:29:36 2006'
<0> joedj: iter items isnt a benefit when im using it in a listcomp
<7> ironfroggy: it still allocates less memory
<2> Still hex...
<2> uploading what there is.
<0> alright does that work?
<2> I get hex.
<0> what do you mean you get hex?
<5> Jerbear: You were asking how to go from datetime.utcnow() to local-time, yes?
<1> pythy: yes
<2> <__main__.Card object at 0x00AFDCD0>
<2> that
<2> That's with the fix + .items()



<0> Wolfman2000: well of course, we havent added anything to Card yet, have we?
<0> but test that nameOf works by itself.
<2> repr(card) calls nameOf, so it seems to work.
<5> jerbear: So is what I pasted is the solution to your problem?
<0> Wolfman2000: no it doenst
<2> it works without errors. I just haven't gotten it to print the string right yet.
<5> Jerbear: >>> dto = datetime.datetime.utcnow(); t = dto.timetuple()[:6]
<5> >>> print datetime.datetime.fromtimestamp(calendar.timegm(t)) #==> 2006-05-28 00:34:37
<0> Wolfman2000: repr(card) doesnt touch nameFor or nameOf
<1> pythy: i would prefer to not deal with unix timestamps. this is such a common operation when dealing with databases, in general, that i find it baffling that there is not a more elegant solution
<2> ...repr(card) goes to Card, not Deck...
<2> Is that what you are saying?
<0> repr(X) is the same as doing X.__repr__()
<5> jerbear: what part of my solution would you which to be different, and how?
<5> jerbear: what part of my solution would you >wish< to be different, and how?
<2> ironfroggy: That statement doesn't really tell me much of anything.
<0> Wolfman2000: repr(card) doesnt deal with Deck
<2> It deals with Card.
<2> ...I was working with Deck though. Was that the main issue?
<1> pythy: i guess it's fine, if it works. i'm just stunned that there is no solution that is cleaner
<5> jerbear: you supply tuple t, I call one function to convert it (I can write my own implementation of that function in one line, if you prefer), and instantiate a new object. What part should be cleaner, and how?
<2> okay...I'm closer now I think. I at least get the text "Rank of Suit" 5 times. Uploading what I got now.
<2> up
<1> pythy: i was hoping there would be a way to stay within the realm of the datetime object. converting values as sensitive as time makes me nervous
<4> jerbear: my way does that :P
<4> <4> >>> datetime.datetime.now() - datetime.datetime.utcnow()
<4> <4> datetime.timedelta(-1, 75600)
<4> <4> >>> datetime.datetime.now() + datetime.timedelta(-1, 75600)
<4> <4> datetime.datetime(2006, 5, 27, 14, 36, 42, 470000)
<0> brb
<5> "to stay within the realm of the datetime object" > jerber: But you're not: You're handing me a six-element tuple at the outset, that's predicated on a different timezone.
<8> From the I-Think-I-Probably-Missed-Something-Obvious department: is there a way to iterate over the contents of a file byte-by-byte?
<5> jerber: So, I call a function (which I can re-write in a line for you, if using the calendar-module makes you nervous) to shift it, & instantiate the date-time object.
<7> Vornicus: use a while loop and read 1 byte each time, or read bigger chunks/lines and iterate over those
<1> pythy: how would you avoid the calendar module?
<5> jerber: By writing my own version of that function, which is probably a one-liner.
<8> ...oh yeah, I forgot you could get individual characters by iterating over a string.
<9> Vornicus: while 1: f.seek(1)
<5> jerber: But, in scrolling up, I see you stuck with no solution for quite a while; if your issue now is over calling the given function to do the conversion you sought, I'd call that progress. ;-)
<7> you can also do something like bytes = iter(lambda: f.read(1), '') and use a for loop
<10> what's the best way to check if a process is running?
<1> pythy: what if i wanted to go the other direction.. localtime->utc?
<9> ps
<5> utcfromtimestamp, utcnow, utcoffset, utctimetuple
<8> That'll do it. Cool. Thank you both!
<7> pembo13: os.kill(pid, 0) usually returns None if the process exists, or raises OSError. not sure how portable this is
<0> Wolfman2000: why did you put a nameOf on Card?
<10> joedj: but i don't want to kill the process, and only have the process name
<1> pythy: i would definitely consider our discussion progress, and i appreciate the help..
<7> pembo13: it doesn't actually send a signal. but you need the pid
<4> pembo13: poll( )
<4> Check if child process has terminated. Returns returncode attribute.
<4> subprocess.Popen
<10> hm
<10> ok
<0> Wolfman2000: the reason you are just getting "Rank of Suit" is because the only rank and suit attributes a card has are its own, and only by the names "rank" and "suit". thats why you need the Deck to get the names.
<2> From Card, should I call Deck.nameOf then?
<0> yes
<5> jerbear: The docs for the datetime-module are the problem.
<0> well..
<2> ...not quite
<0> Wolfman2000: you should give the cards a deck attribute, for the case that the card doesnt really know what Deck cl*** made it.
<2> index error: out of range
<1> pythy: so the bottom line is the best way to handle going back and forth between utc and localtime would be to use a combination of timetuples and epoch timestamps?
<4> jerbear: do yourself a huge favor and visit http://pytz.sourceforge.net/ :)
<0> and you definately shouldnt create new instance sof Deck for every time you call nameOf like that
<0> hah
<2> We'll try to meet up again another time.
<5> jerbear: Whatever works. ;-)
<1> ajaksu: i've already gone through the docs for pytz, i didn't find a satisfactory solution
<0> Wolfman2000: pm me your email again, i lost it.
<0> Wolfman2000: ill fix what we have.


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #python
or
Go to some related logs:

xlibs-dev debian 6.9
#php
#gentoo
#css
Websuraj
#linux
xubuntu lspnp
create_table_from_dump: failed in handler::
#web
#debian



Home  |  disclaimer  |  contact  |  submit quotes