Newbie: strftime object error message

F

fuglyducky

I am trying to call a function with a couple additional parameters.
Unfortunately, for whatever reason I am unable to get this to work. I
am assuming that line is not passing correctly but I don't understand
why???

I can't share all of the code because it has IP in it but below are
the pertinent snippets.

Thanks in advance!

##################################################################################

PY: 3.1.2


FUNCTION CALL:
text_file = open(file_name, "r")
for line in text_file:
new_foo = pop_time(current_time, line)
# current_time = datetime.datetime.now()


FUNCTION:
def pop_time(line, cur_time):
global new_string
global current_time


# Generate random time between 0 and 30 seconds
# Changes the time delta every time function is run
rand_time = random.randint(0, 30)
delta_time = datetime.timedelta(seconds=rand_time)

# Sets the time format for string output
format_time = cur_time.strftime("%Y-%m-%d %H:%M:%S")


ERROR MSG:
format_time = cur_time.strftime("%Y-%m-%d %H:%M:%S")
AttributeError: 'str' object has no attribute 'strftime'


NOTE: current_time prints within the function, line does not
 
M

Mark Lawrence

I am trying to call a function with a couple additional parameters.
Unfortunately, for whatever reason I am unable to get this to work. I
am assuming that line is not passing correctly but I don't understand
why???

I can't share all of the code because it has IP in it but below are
the pertinent snippets.

Thanks in advance!

##################################################################################

PY: 3.1.2


FUNCTION CALL:
text_file = open(file_name, "r")
for line in text_file:
new_foo = pop_time(current_time, line)
# current_time = datetime.datetime.now()


FUNCTION:
def pop_time(line, cur_time):

Look at the two arguments to pop_time, when you make the actual call
they are swapped.
global new_string
global current_time


# Generate random time between 0 and 30 seconds
# Changes the time delta every time function is run
rand_time = random.randint(0, 30)
delta_time = datetime.timedelta(seconds=rand_time)

# Sets the time format for string output
format_time = cur_time.strftime("%Y-%m-%d %H:%M:%S")


ERROR MSG:
format_time = cur_time.strftime("%Y-%m-%d %H:%M:%S")
AttributeError: 'str' object has no attribute 'strftime'


NOTE: current_time prints within the function, line does not

HTH.

Mark Lawrence.
 
M

MRAB

fuglyducky said:
I am trying to call a function with a couple additional parameters.
Unfortunately, for whatever reason I am unable to get this to work. I
am assuming that line is not passing correctly but I don't understand
why???
[snip]
The function's parameters are the wrong way round.
 
F

fuglyducky

Look at the two arguments to pop_time, when you make the actual call
they are swapped.








HTH.

Mark Lawrence.

Oh jeez!!! Thanks! Man...looking at this stuff for so long it's easy
to miss the obvious!!! Thanks and sorry for the waste of time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top