I get a "TypeError: must be str,not tuple"

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 33330 Views - Last Post: 20 December 2015 - 03:44 PM Rate Topic: -----

#16 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: I get a "TypeError: must be str,not tuple"

Posted 19 December 2015 - 05:25 PM

Dunno off the top of my head, but a quick search finds..

How do I print a Python datetime in the local timezone?
Was This Post Helpful? 0
  • +
  • -

#17 travo123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-December 15

Re: I get a "TypeError: must be str,not tuple"

Posted 20 December 2015 - 04:26 AM

Iv read that page .. but not sure though how im going to apply it in my case. I have a list with many rows of datetime objects, which I want to convert to local timezone.
Feels like there is many commands/libraries for this issue , which makes me kinda confused.
Was This Post Helpful? 0
  • +
  • -

#18 travo123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-December 15

Re: I get a "TypeError: must be str,not tuple"

Posted 20 December 2015 - 04:52 AM

Forgot to mention: The current timezones are in UTC, but i want to convert them into local timezone.
Was This Post Helpful? 0
  • +
  • -

#19 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: I get a "TypeError: must be str,not tuple"

Posted 20 December 2015 - 04:53 AM

Explore. Experiment. In particular, if you are not following a structured tutorial, then this is what you need to do.
Was This Post Helpful? 0
  • +
  • -

#20 travo123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-December 15

Re: I get a "TypeError: must be str,not tuple"

Posted 20 December 2015 - 05:05 AM

Yea will try do so .. but kinda hard with python , since there is not so much material out there compared to bigger programming languages.
Was This Post Helpful? 0
  • +
  • -

#21 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: I get a "TypeError: must be str,not tuple"

Posted 20 December 2015 - 05:39 AM

I disagree. But this is the path you've chosen by not undertaking formal, structured, learning with a book or sequence of tutorials. You've effectively said "I don't need a book, I can work it out myself".

(I presume this because you did not respond when I asked which tutorial you were following, and because of the significant gaps in your knowledge. E.g. string concatenation.)

I'll drop out now. Maybe someone else will assist you. Good luck.

This post has been edited by andrewsw: 20 December 2015 - 05:40 AM

Was This Post Helpful? 0
  • +
  • -

#22 travo123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-December 15

Re: I get a "TypeError: must be str,not tuple"

Posted 20 December 2015 - 03:44 PM

Ok andrew no problem ;P

Anyone who could help me out?
I'v played around with some codes now on converting strings to local timezone from utc.
For example:
now_utc=datetime.utcnow()
local_tz = pytz.timezone('Europe/Stockholm')
now_utc = pytz.utc.localize(now_utc)
local_time = now_utc.astimezone(local_tz)



But Im not really sure on how to do the same for my list containing sevral rows with datetime objects?
In this case it is the newList I would like to convert into local timezone:
file=open("datafile.txt","r") 
newList=[]
for line in file: 
      frmt = '%Y-%m-%d %H:%M:%S.%f'  
      a,b,c=line.split()    
      newList.append(datetime.datetime.strptime(a + " " +b, frmt))


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2