+ 1
How to make function that takes string argument without typing " " from the user?
6 Answers
+ 6
Could you be more specific? input() returns string by default, so you shouldn't have a problem with what the user types...
+ 5
Can't do it. The syntax expects data in either an explicit form or otherwise it treats the argument as a variable name.
+ 5
@merkrafter Just out of curiosity - how would that go?
+ 1
For example:
def name(word):
print word
name("hesham")
How to make it accept writing hesham instead of "hesham"
0
You could write another program that keeps track of all variable names. Then, if you call a function with an unknown variable name, it puts these " " around it.
This would work as a kind of a preprocessor.
0
Unfortunally I am not a python expert, but I think you can make a list of variable names and take a file name.
Then you read the file, search for "NAME=" declarations and add the NAME to your list.
If you find another word followed by parenthesis, you can interpret it as a function and then check the arguments for being a number, a variable or a possible string.
This is not the perfect approach, but it could theoretically work, right?
I think regular expressions could come handy.