Skip to main content

All Questions

0 votes
1 answer
141 views

How to format an argument inside a function but also print the string as many times as the argument

I am a beginner and was just messing around with functions and i thought of the code below. I want to print the strings as many times as whatever the value of a is going to be, but i also want to ...
Ckrielle's user avatar
0 votes
1 answer
54 views

Not receiving a return message in python 2 code

I'm pretty new to python and just learning to ropes. In the code bellow I have a function taking several inputs from a json string. I'm attempting to have a return output in the specified strings. ...
Manuela Arboleda's user avatar
-1 votes
1 answer
49 views

String within function in python

I want to write a function in python that reads in my data. Outside this function, something like this works model = open_ncfile('/data/BAF_2001-2013_model.nc') lat_model = model.variables['lat'][:] ...
scriptgirl_3000's user avatar
0 votes
2 answers
44 views

Preserve Original Parameter Value between Recursive Calls (Python 2.7)

Observe the following Python 2.7 function: def replace(c, st): if st == "": return [] else: temp = [st + c] c += c return temp + replace(c, st[:-1]) print replace("z", "Howdy") ...
EllipticalInitial's user avatar
-1 votes
1 answer
33 views

How to use strings as name to define a function?

What I want: I want to use string to be name of a function, I am defining. Code to reproduce result: def creator(string): def string(): return 0 return string So the creator function ...
udayanmaurya's user avatar
2 votes
1 answer
5k views

TypeError: unsupported operand type(s) for +: 'bool' and 'str' in Odoov10

I got following error when applying function in Odoov10. TypeError: unsupported operand type(s) for +: 'bool' and 'str'. My Python code is here: @api.multi def name_get(self): result = [] ...
Pawan Kumar Sharma's user avatar
0 votes
2 answers
887 views

Define function to convert string to integer in Python

This is likely a very simple question but I would appreciate help! As part of a larger script, I have a dataframe (imported from a csv file) with two columns, 'file_name' and 'value'. I have a short ...
ailsa_naismith's user avatar
0 votes
1 answer
267 views

Convert string stored in string to a function (Python) [duplicate]

If I have the name of a function stored in a string like so: foo = 'some_function' Assuming that I could call bar.some_function.baz(), how can I do that using foo? Obviously this example doesnt ...
SneakyOrc's user avatar
0 votes
2 answers
59 views

How do you combine variables to form function in python?

ypos = 1 ypos2 = ypos-1 xpos = 1 xpos2 = 2 Using these variables, that are changed each time the code loops, how do I get it to print the result below? =B(ypos)-B(ypos2) Every time the code loops the ...
Binary111's user avatar
  • 159
-5 votes
2 answers
1k views

Function creation - "Undefined name" - Python

I'm writing some code that reads words from a text file and sorts them into a dictionary. It actually all runs fine, but for reference here it is: def find_words(file_name, delimiter = " "): """ A ...
Stuart Aitken's user avatar
0 votes
1 answer
115 views

a function that performs a task similar to the string.replace() method in python

i am working on this python function, which should take three parameters: The first, called the content string, can be any string. The second, called the token, should be a string containing a single ...
arsalunic612's user avatar
3 votes
3 answers
860 views

Adding print statement to ValueError exception

New to Python, so I'm sure this is a noob question, but Googling isn't availing me of a clear answer. Given the following function which is intended to ensure that the user input is a string, why ...
SeanJarp's user avatar
  • 129
0 votes
2 answers
176 views

Understanding recursive string reversal

I'm using the Python Tutorial visualize webpage to try and understand the flow of this function that reverses a string: text = "hello" def reverse(text): if len(text) <= 1: return ...
AdjunctProfessorFalcon's user avatar
0 votes
1 answer
42 views

Use 2 Strings to call Function X from Module Y

So I've been working on a Menu Handler for one of my text games so that making menus would take up less space on a player's hard drive, but after using a piece of code I found here on stackOverflow, I ...
1SDANTheMan's user avatar
-3 votes
2 answers
62 views

I need to improve python function that works with loops and string how it does?

I have such problem I have this piece of code on python2.7. It works approximately 60 seconds for object with slightly more than 70000 items in the object. How it works? It gets an object with paths ...
Dmytro Chasovskyi's user avatar

15 30 50 per page