Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Juan Christian
On Fri, Sep 19, 2014 at 10:50 PM, Cameron Simpson wrote: > On 19Sep2014 20:46, Juan Christian wrote: > >> On Fri, Sep 19, 2014 at 8:22 PM, Danny Yoo >> wrote: >>Anyway, can you use ctime()? It looks like that might be almost right: >>>>> t = 1411167038 >>>>> datetime.dateti

Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Cameron Simpson
On 19Sep2014 20:46, Juan Christian wrote: On Fri, Sep 19, 2014 at 8:22 PM, Danny Yoo  wrote: Anyway, can you use ctime()?  It looks like that might be almost right:     >>> t = 1411167038     >>> datetime.datetime.utcfromtimestamp(t).ctime()     'Fri Sep 19 22:50:38 2014' The thing

Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Juan Christian
On Fri, Sep 19, 2014 at 9:24 PM, Juan Christian wrote: > So.. It seems all my problem was in the .strftime("%D %H:%M") > > I don't exactly know why, but I removed and it's working. It's not giving > me the localtime, but I'll search how to do that. > Ops, my bad again, it's indeed in the localti

Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Juan Christian
So.. It seems all my problem was in the .strftime("%D %H:%M") I don't exactly know why, but I removed and it's working. It's not giving me the localtime, but I'll search how to do that. ___ Tutor maillist - Tutor@python.org To unsubscribe or change sub

Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Juan Christian
On Fri, Sep 19, 2014 at 8:22 PM, Danny Yoo wrote: > Huh. I should have read your message more closely. Sorry; it's been > one of those days for me, it seems... > > Anyway, can you use ctime()? It looks like that might be almost right: > > >>> t = 1411167038 > >>> datetime.datetime.utcf

Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Danny Yoo
Huh. I should have read your message more closely. Sorry; it's been one of those days for me, it seems... Anyway, can you use ctime()? It looks like that might be almost right: >>> t = 1411167038 >>> datetime.datetime.utcfromtimestamp(t).ctime() 'Fri Sep 19 22:50:38 2014' though i

Re: [Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Danny Yoo
On Fri, Sep 19, 2014 at 4:00 PM, Juan Christian wrote: > Let's say I have ' 1411167038 ' string that I got from an API and I need to > convert it to something like ' Fri, 19 Sep 2014 22:50:38 GMT ' or maybe even > the localtime of the PC. What does that number mean though? Let me guess: is it th

[Tutor] Converting timestamp read as str to "full date and time"

2014-09-19 Thread Juan Christian
Let's say I have ' 1411167038 ' string that I got from an API and I need to convert it to something like ' Fri, 19 Sep 2014 22:50:38 GMT ' or maybe even the localtime of the PC. I'm trying this way: my_date = datetime.datetime.fromtimestamp(api['backpack_update'][GAME_ID]).strftime("%D %H:%M") T

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Peter Otten
Juan Christian wrote: > On Fri, Sep 19, 2014 at 4:30 PM, Peter Otten <__pete...@web.de> wrote: >> >> Well, you import closing from the stdlib with >> >> from contextlib import closing >> >> and then proceed to write your own closing >> >> @contextmanager >> def closing(thing): >> try: >>

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Juan Christian
On Fri, Sep 19, 2014 at 4:30 PM, Peter Otten <__pete...@web.de> wrote: > > Well, you import closing from the stdlib with > > from contextlib import closing > > and then proceed to write your own closing > > @contextmanager > def closing(thing): > try: > yield thing > finally: >

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Peter Otten
Juan Christian wrote: > This is the code using the contextlib (more than 105 lines): > http://pastebin.com/jVhz7Ta6 > > But I'm getting another (super confusing) error now: > > [#] [Tf2 inventory [W]CS GO Skins > Author: Pnoy Paragon << UNTIL HERE, OK! > > Traceback (most recent call la

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Juan Christian
On Fri, Sep 19, 2014 at 3:53 PM, Peter Otten <__pete...@web.de> wrote: > > If I understand you correctly you can test for the presence of a value. > Example: > > api = response.json()['response']['players'][steamID64] > status["steamrep_scammer"] = "steamrep_scammer" in api Thanks, this way I can

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Juan Christian
This is the code using the contextlib (more than 105 lines): http://pastebin.com/jVhz7Ta6 But I'm getting another (super confusing) error now: [#] [Tf2 inventory [W]CS GO Skins Author: Pnoy Paragon << UNTIL HERE, OK! Traceback (most recent call last): File "C:\Users\Juan Christian\Desk

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Peter Otten
Juan Christian wrote: > On Fri, Sep 19, 2014 at 3:15 PM, Peter Otten <__pete...@web.de> wrote: >> >> Let's take a step back: if you were to write >> >> > with requests.get(''.join([BACKPACKTF, steamID64])) as response: >> > status = {'profile': ''.join([BACKPACKTF, steamID64]),'backpack_value': >>

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Danny Yoo
>> class AutoClosable(object): [cut] > There is also > > Ah, much better! Thanks Peter. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: h

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Juan Christian
On Fri, Sep 19, 2014 at 3:15 PM, Peter Otten <__pete...@web.de> wrote: > > Let's take a step back: if you were to write > > > with requests.get(''.join([BACKPACKTF, steamID64])) as response: > > status = {'profile': ''.join([BACKPACKTF, steamID64]),'backpack_value': > > 'Private or invalid', 'steam

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Peter Otten
Danny Yoo wrote: > I should have added that you can write your own context manager for > requests; it shouldn't be too bad. I'd expect the helper code to be > something like: > class AutoClosable(object): > def __init__(self, closable): > self.closable = closable > > def __enter

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Danny Yoo
I should have added that you can write your own context manager for requests; it shouldn't be too bad. I'd expect the helper code to be something like: # class AutoClosable(object): def __init__(self, closable): self.closable = closable def

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Peter Otten
Juan Christian wrote: > This part of my code isn't working: > > def check_backpacktf(steamID64): > with requests.get(''.join([BACKPACKTF, steamID64])) as response: > status = {'profile': ''.join([BACKPACKTF, steamID64]),'backpack_value': > 'Private or invalid', 'steamrep_scammer': False} > > wit

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Joel Goldstick
On Fri, Sep 19, 2014 at 2:00 PM, Juan Christian wrote: > On Fri, Sep 19, 2014 at 2:50 PM, Danny Yoo wrote: >> >> So Python's "with" appears to require a bit more out the thing being >> managed than the similar try-with-resources in Java. >> >> (http://docs.oracle.com/javase/tutorial/essential/exc

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Juan Christian
On Fri, Sep 19, 2014 at 2:50 PM, Danny Yoo wrote: > > So Python's "with" appears to require a bit more out the thing being > managed than the similar try-with-resources in Java. > ( > http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html > ) > Is there anything simila

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Danny Yoo
> Traceback (most recent call last): > File "C:\[...]\shark.py", line 98, in > main(sys.argv[1]) > File "C:\[...]\shark.py", line 93, in main > fetch_forum() > File "C:\[...]\shark.py", line 79, in fetch_forum > fetch_user(user_url) > File "C:\[...]\shark.py", line 42, in fetch

Re: [Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Joel Goldstick
On Fri, Sep 19, 2014 at 1:30 PM, Juan Christian wrote: > This part of my code isn't working: > > def check_backpacktf(steamID64): > with requests.get(''.join([BACKPACKTF, steamID64])) as response: I'm not sure why my reply mangled your indents, but can you check to see that your "".join() is gett

[Tutor] Using 'requests' + 'with statement' in Python 3.4.1

2014-09-19 Thread Juan Christian
This part of my code isn't working: def check_backpacktf(steamID64): with requests.get(''.join([BACKPACKTF, steamID64])) as response: status = {'profile': ''.join([BACKPACKTF, steamID64]),'backpack_value': 'Private or invalid', 'steamrep_scammer': False} with response.json()['response']['players'

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Thank you Peter Otten, actually i should study about the collections and defaultdict like how and where these can be used and its advantage. On Fri, Sep 19, 2014 at 5:59 PM, Peter Otten <__pete...@web.de> wrote: > Sunil Tech wrote: > > > Danny i did it like this > > > > result_dict = {} > > fo

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Peter Otten
Sunil Tech wrote: > Danny i did it like this > > result_dict = {} > for i in tes: > if i['a'] in result_dict: > temp = result_dict[i['a']] > temp['b'].append(i['b']) > temp['c'].append(i['c']) > temp['a'] = i['a'] > result_dict[i['a']] = temp > else

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Danny i did it like this result_dict = {} for i in tes: if i['a'] in result_dict: temp = result_dict[i['a']] temp['b'].append(i['b']) temp['c'].append(i['c']) temp['a'] = i['a'] result_dict[i['a']] = temp else: result_dict[i['a']] = {

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Danny Yoo
On Sep 19, 2014 12:28 AM, "Danny Yoo" wrote: > > > >{'a': 2, 'b': 'another', 'c': 754}, > >{'a': 2, 'b': 'word', 'c': 745} > > > > > if the value of the 'a' is same, then all those other values of the dict should be merged/clubbed. > > Can you write a function that takes two of the

Re: [Tutor] Is there any XML lib like the default json lib in terms of usability?

2014-09-19 Thread Peter Otten
Juan Christian wrote: > Using the default json lib is easy and straightforward: > > import json > info = json.loads('file.json') > # Use dict and list to navigate through 'info' > > > Sadly, I'm working in a script and the only format the server gives is > XML, I searched for a good alternative

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Danny, i wrote a method called *merge *below can you be little clear with an example I wrote something like this ​​ ids = [] for i in tes: if i['a'] not in ids: ids.append(i['a']) print ids def merge(ids, tes): for jj in ids: txt = '' for i in tes: i

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Danny Yoo
>{'a': 2, 'b': 'another', 'c': 754}, >{'a': 2, 'b': 'word', 'c': 745} > > if the value of the 'a' is same, then all those other values of the dict should be merged/clubbed. Can you write a function that takes two of these and merges them? Assume that they have the same 'a'. Can