0
votes
2answers
43 views

Pass variable contents to class function in Python

I'm trying to pass the contents of a variable to a function within a class that's run as a thread. How would I do this? Following is some pseudo code that should have the output following. The ...
3
votes
5answers
37 views

Local and global variables in python functions

I started learning python few weeks ago (with no prior knowledge of programming). I know I am a bit tiresome with repeating the upper sentence over and over, but that' just to tell you that I might ...
0
votes
1answer
23 views

python load from shelve - can I retain the variable name?

I'm teaching myself how to write a basic game in python (text based - not using pygame). (Note: I haven't actually gotten to the "game" part per-se, because I wanted to make sure I have the basic core ...
1
vote
4answers
104 views

Is using “try” to see if a variable is defined considered bad practice in Python?

I have the following piece of code inside a function: try: PLACES.append(self.name) except NameError: global PLACES PLACES = [self.name] Which causes from <file containing that ...
0
votes
1answer
26 views

Number in a radius calc trouble python

Here is the formula for the radius import math def calculateDistance( latOne, lonOne, latTwo, lonTwo ): DISTANCE_CONSTANT = 111120.0 coLat = math.fabs(lonOne - lonTwo) alpha = 90 - latTwo beta = ...
1
vote
2answers
34 views

Global Variables in functions with if statements

Okay, I am currently doing a project to make a blackjack game in python and I'm having some trouble. One of my issues is I dont know when to define a variable as global, specifically in functions ...
0
votes
2answers
35 views

Choosing variables to create when intializing classes

I have a class which would be a container for a number of variables of different types. The collection is finite and not very large so I didn't use a dictionary. Is there a way to automate, or shorten ...
0
votes
5answers
49 views

python: how to identify if a variable is an array or a scalar

I have a function that takes the argument NBins. I want to make a call to this function with a scalar 50 or an array [0, 10, 20, 30]. How can I identify within the function, what the length of NBins ...
0
votes
2answers
56 views

Send a Variable from one Python Script to another

I have a python script that is constantly listening out for a json message from another server. When it receives a message one of the values is placed into a variable. Once this message is received I ...
0
votes
1answer
20 views

Using raw_input() without assigning a variable

I've only recently begun learning python2, and this is the way I see raw_input(). If suppose I write name = raw_input("What's your name? ") then I ask the user to enter something which gets stored as ...
0
votes
1answer
58 views

change and pass a global variable to function Python

I have a recursive function as below which changes the global variable but it seems that i cannot pass the changed global variable to the recursive function since the error exceptions says: File ...
0
votes
1answer
49 views

Python default values for class member function parameters set to member variables

I am running into a problem writing recursive member functions in Python. I can't initialize the default value of a function parameter to be the same value as a member variable. I am guessing that ...
2
votes
1answer
28 views

Tkinter variable definition, which is more desirable?

I am new to Tkinter and I was wondering which of the following way to set variables is more desirable: class App(): def __init__(self,master): self.var1 = StringVar() <filler> ...
2
votes
1answer
31 views

What is the difference of lifetimes of compound types and scalar types?

The following is an except from a tutorial. The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most ...
1
vote
1answer
38 views

Python outputs only after script has finished in Komodo Edit

Forgive me if it's a silly question. I'm new to Python and scripting languages. Now I'm using Komodo Edit to code and run Python programs. Each time I run it, I have to wait until the program finished ...
4
votes
2answers
72 views

Python 3 How do I 'declare' an empty `bytes` variable

How do I 'declare' an empty bytes variable in Python 3? I am trying to receive chunks of bytes, and later change that to a utf-8 string. However, I'm not sure how to declare the initial variable that ...
0
votes
2answers
60 views

Extract value from a list in another function in Python

I am programming a robot and I want to use an Xbox Controller using pygame. So far this is what I got (original code credits to Daniel J. Gonzalez): """ Gamepad Module Daniel J. Gonzalez ...
0
votes
3answers
43 views

Determining if a Variable is Numerically an Integer in Python

I'm having an issue with determining if a variable is an integer. Not the variable type, but the actual value stored in the variable. I have tried using variable % 1 as a test, but it does not seem to ...
0
votes
2answers
51 views

Euler's Method Python Variable Input Type

I'm having an issue with the following code. It's currently in progress but a large problem that I'm running into is that my input of a function returns an error no matter what type of input I have ...
0
votes
5answers
45 views

Strings with embedded variables in Python

Maybe some already asked this but I didn't find it and I wanted to know how to embed variables into a string in Python. I usually do it like this: print('Hi, my name is %s and my age is %d' %(name, ...
0
votes
1answer
52 views

Inserting Variables MySQL Using Python, Not Working

I want to insert the variable bob, and dummyVar into my table, logger. Now from what I can tell all I should need to do is, well what I have below, however this doesn't insert anything into my table ...
-5
votes
3answers
71 views

I need help creating a program that randomizes numbers and variables [closed]

I am trying to get this program to work, and I am failing miserably. I am trying to create a card game that randomizes my variables(they are defined) and numbers. So basically, you draw two random ...
0
votes
2answers
45 views

using a variable from a method of another class in python

I have code that goes like this: class A(object): def __init__(self, master): """Some work here""" def do_this(self): self.B = B.do_that() print self.B[1] ...
0
votes
5answers
86 views

How to check if a variable is an integer or a string? [duplicate]

I have an application that has a couple of commands. When you type a certain command, you have to type in additional info about something/someone. Now that info has to be strictly an integer or a ...
1
vote
4answers
68 views

I want to refer to a variable in another python script

A variable AA is in aaa.py. I want to use this variable in my other python file bbb.py How do I access this variable?
0
votes
3answers
27 views

Looping with a while statement while reading a string for an integer

I need help encasing the: if any(c.isdigit() for c in name): print("Not a valid name!") inside of a while statement. This pretty much just reads the input for the "name" variable and sees if ...
2
votes
2answers
87 views

Python class variable not updating

I have a class that is taking in an Id and trying to update the variable current_account but when I print out the details of the current_account it hasn't updated. Anyone got any ideas for this? New ...
-5
votes
1answer
71 views

The letter 'n' is invalid syntax in Python? [closed]

It was working as a variable name earlier in my program now all of a sudden Python keeps returning the letter 'n' as invalid syntax in my program. Any idea why, and how to fix this? bad_input=True ...
0
votes
1answer
45 views

Python: 'Refresh' specific variables within a script

Alrighty, so I have this python script that copies text from multiple files and pastes it to new files of a different file extension. It's almost done however I have a problem with its refresh button. ...
0
votes
1answer
42 views

Python: From outside Class access to variable in method other than __self__(init)

There is an example at http://effbot.org/tkinterbook/tkinter-dialog-windows.htm and one thing I don't understand: class Dialog(Toplevel): ... self.result = None ... class ...
1
vote
2answers
39 views

How to call variables generated in loop

I need to generate a number of variables in a loop. I achieved this by using this code: nBottom=list of initially unknown size loc=locals() for k,val in enumerate(nBottom) : ...
0
votes
3answers
70 views

Add variable name to variable

I have the following variable: VarX=700 I now need to write the name of VarX into a txt file. So I'm thinking I need to create another variable and assign to it the name of VarX and then write it ...
2
votes
2answers
43 views

Include user named variables in existing python script

Imagine you have program X that needs the following input by the user: fy = 355. #Yield stress (MPa) fu = 552. #Tensile stress resistance (MPa), 460 MPa in engineering stress E = 210.E3 #Young ...
1
vote
4answers
86 views

Is it possible to create a variable as a placeholder for 'current' value of a class in python?

Let's say we have a class: NOTE: this is a dummy class only. class C(object): def __init__(self): self.a = -10 self.b = 5 self.c = 2 def modify(self, **kwargs): ...
0
votes
3answers
59 views

Using gnuplot to generate a set of numbered images

I'm a newbie in Python and I would like to ask you, how can I get images (a lot of images) made by Gnuplot.py with variable in name? I have this function, which creates single image: def ...
2
votes
3answers
76 views

Set class (self) variables from variables?

This is poor programming practice, yes, I know, but these scripts are purely mine and this technique would ease my coding a lot. Right now, I have an SQLite database containing a set of key-value ...
0
votes
5answers
62 views

How to add variables in Python? [closed]

Python noob here. I'm trying to add a set of input variables defined in an 'if' statement and whenever I try to find the sum it will just display the values inline. For example, when a, b, c, and d ...
0
votes
2answers
38 views

How to use classes to access a variable in function_one from function_two?

Contents of file_one.py: from file_two import * def function_one(): my_list = [] function_two() function_one() Contents of file_two.py: def function_two(): my_list.append(1) ...
0
votes
3answers
28 views

Little NumPad in tkinter

I'm trying to build a little num pad using tkinter, to be able to enter a password code on a pure touchsystem. This is what I have so far: import tkinter from tkinter import ttk def main(): root ...
1
vote
2answers
53 views

2-dim Dictionary, key as a string

I have a possibly simple Question but I haven't found a solution, yet. I am trying to acces a 2-dim dictionary with the help of a string varialbe, but cannot access it correctly. It is really ...
0
votes
3answers
103 views

Is there a difference between “variables being names” and “variables being storage”?

I've heard and read everywhere that variables are "names, not storage" in Python, and that it's important to not think of them like storage, but I've not found a single example of why that would be ...
-1
votes
1answer
34 views

Error while printing variable interpolation in python [closed]

I am python newbie and facing trouble with variable interpolation concept in python I have written a method to check the argument but it giving error while printing the line import re import ...
1
vote
2answers
67 views

Python class instances stored in a list to store seperate instances

from datetime import datetime class sms_store: def __init__(self): self.store = [] #Keeps resetting / not saving data from previous instances self.message_count = 0 #Keeps ...
1
vote
3answers
58 views

How to link two depended inputs of unknown size with variables

This is my first python script. My data looks like this: Position ind1 ind2 ind3 ind4 ind5 ind5 ind7 ind8 0 C A C A A A A A 1 C A C C C A A ...
0
votes
1answer
39 views

Global name error

I am still pretty new to Python, so I'm sorry if my question is trivial or even stupid. I am trying to build a little module that reacts on a callback of a Button (which isn't in the code). The ...
0
votes
1answer
42 views

Replacing variable with values from a CSV-file in python

I have a csv file with the following format: variable, name, date, location, youtube, e1, My birthday, 21st april, USA, www.xyz.com e2, your b'day, 1st May, India, ...
0
votes
1answer
57 views

Python3: string to variable

I've looked everywhere for this but haven't found a suitable answer yet and I don't want to use a dictionary. How can I convert a string to a variable name? For example I have this call: ...
4
votes
1answer
79 views

What's the difference between class variables of different types?

Firstly, there is class A with two class variables and two instance variables: In [1]: def fun(x, y): return x + y In [2]: class A: ...: cvar = 1 ...: cfun = fun ...: def ...
0
votes
1answer
33 views

IndexError: list index Python when Parsing Elements from XML file

I am very new to python however I have managed to create a parser python program which calls a web-based xml file and stores elements within an array. These arrays containing the xml elements are then ...
2
votes
2answers
138 views

What is the difference between literal and variables in Python? [closed]

I'm a beginner user for Python, but I get confused between literal and variables. This is what I know about a literal: "a"+"b" And variables: sentence="a"+"b"

1 2 3 4 5 16
15 30 50 per page