Py3k identical code executing differently in dynamic shell and from file [closed] - python-3.x

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
The code I'm using is:
import time
print(time.strftime("%H:%M:%S"))
In the dynamic shell, this (as you would expect) outputs a formatted string, e.g. 03:21:35
When executing the exact same code from a file, it throws the following error:
Traceback (most recent call last):
File "main.py", line 2, in <module>
print(time.strfime("%H:%M:%S"))
AttributeError: 'module' object has no attribute 'strfime'
Anybody got any idea as to why this might be happening, and more importantly, how to fix it?

You've got a typo:
print(time.strfime("%H:%M:%S"))
should be
print(time.strftime("%H:%M:%S"))

Related

How can I link multiple files on python, it is very annoying while writing a very long codes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I’m new to python, I’m writing a code which requires multiple files because the code is getting bigger and bigger and it’s hard for me to figure out errors, someone should help
You can have a Python file with a number of functions in it and call functions from other scripts. For example, you could name the file myfunctions.py and it could contain a function called function_one. If it is saved in the same directory as the Python script you are running, you can run it by
import myfunctions
myfunctions.function_one()

why does result() take no arguments? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
class result:
def _init_(self,phy,chem,math):
self.phy=phy
self.chem=chem
self.math=math
def printavg(self):
print(f"average={(self.phy+self.chem+self.math)/3}")
rollone=result(86,95,85)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: result() takes no arguments
getting the same error again and I used init constructor in the right way
is anyone to explain is most welcome and benevolent of you?
Your declaration of init is wrong, it is __init__ and not _init_, ie, with double underscores :
class result:
def __init__(self,phy,chem,math):
self.phy=phy
self.chem=chem
self.math=math
def printavg(self):
print(f"average={(self.phy+self.chem+self.math)/3}")

In Perl, what is the efficient way to replace a String dynamically with something else? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a file containing many lines like
"resourcename" : "myfile.pdf",
I want to replace everywhere myfile.pdf with an URL like http://somedomain.com/myfile.pdf. But the file name keeps changing. So if myfile.pdf becomes yourfile.pdf, I want to replace it with http://somedomain.com/yourfile.pdf.
What is an efficient way to do global replacement(/g) without affecting the file's encoding like UTF-8?
Thanks

Haskell ghc main [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am trying to run a haskell script using ghc, however, compiler returns:
The function main is not defined in module Main
Any ideas why this is or what should I do to fix?
Cheers!
ghc is a compiler, so needs a single entry point to run your code.
This is the main function, which should have type IO () and live in your Main module (a module without a module declaration at the top is auto-named Main).
WinHugs is an interpreter - you can run any function you like with any arguments you like.
If you want to use ghc like that, you should use ghci instead - it's ghc's interpreter.
(WinHugs will load your code faster, and ghc will run your code faster.)
To load the script and call functions in an interactive way, run ghci, and then type :load MyScript.hs.

Plotting Lines in Excel [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have data in the following format:
Variable - Value
A 1
B 2
A 3
B 4
and so on.
Notice how the variable is recurring for different values. I want to draw a line for each variable that shows its different values assuming the X-axis is time.
Please any help.
I would start off by creating a Pivot table based on the data that you have and then create the line graph from there.

Resources