0
votes
1answer
45 views

Python Global Variables Confusion

I have some VB code that I'm trying to replicate in Python, but I'm new to Python and its handling of global variables has me completely confused. I have a Python script (pytSettings) that imports ...
0
votes
3answers
35 views

How do I request a variable from the webserver using AJAX?

I have a loop in my JavaScript that is constantly checking the variable EventCounter, if eventcounter is zero then it proceeds to do an action then increment it ++, And then it proceeds to do nothing, ...
2
votes
0answers
47 views

How do I use variables to assign constant arguments in Python? [duplicate]

I'm creating an application in Python using Tkinter where there will be a grid of buttons, and I'm creating the buttons using nested for loops. When clicked, each button has a callback function which ...
-5
votes
2answers
62 views

Python use variables in a list as an argument for a function [closed]

I am having an issue with my python program. Basically, here is what I'm trying to do: categories = [cat1 , cat2] for x in categories: print x print function(x) What I want it to do is ...
0
votes
3answers
64 views

Setting a variable equal to a returned value from a for loop in Python

This would save me a lot of code, but I'm not sure how to implement it. I would like to set my variable "totalfactors" to the result of a for loop iterating through a dictionary and performing a ...
1
vote
3answers
41 views

Python - assigning values to n variables in a for loop

Let's assume that I wanna collect n lists as an input. What I used to do was: l=[] for i in range(n): row=map(int,raw_input().split()) l.append(row) And then I used to access those list by ...
0
votes
2answers
40 views

Python: Values being assigned for wrong IF conditional

I was messing around with Python and was making a little planet simulator. I have one section that is supposed to receive a value and based on that value return a second value. I spent a few hours ...
0
votes
1answer
47 views

producing a variable for input into an RSS feed

this may be a very simple debugging question (I haven't been coding lone) I have a looping code that parses a scraped xml, this parsing happens on a 5 minute loop but doesn't return duplicates from ...
0
votes
0answers
44 views

How to pass variable from view function to jinja2 template - Flask app

I'm writing a basic messaging function inside my app and it does what it's suppose to do. It sends, receives and sort messages in inbox and outbox, and I wanted it to show the nicknames of those who ...
-1
votes
1answer
45 views

What Unicode symbols are accepted in Python3 variable names?

I want to use a larger variety of Unicode symbols for variable names in my Python3 scripts. What characters are acceptable to use in Python3 variable names?
1
vote
2answers
52 views

global/inner variable conflict? (python)

Sorry for the stupid question, I'm a newbie programmer. But can anyone tell me why the following program behaves this way? def lol(a): a=[] a.append(1) return a Now when I do k = [2, ...
0
votes
3answers
52 views

How to use a temporary variable in Python 2.7 - memory

I save 'haystack' in a temporary variable, but when I modify 'haystack', the temporary variable change too. Why? Help please? it's normal? in PHP I didn't have this problem. # -*- coding:utf-8 -*- ...
-2
votes
1answer
67 views

how does “or” work in variable assignments? [duplicate]

How does this work? where is documentation? a = 0 or "" or None or 2 print(a) a = 2 or "" or None or 0 print(a) Thanks.
1
vote
0answers
41 views

Variably variable variables: werkzeug LocalProxy

I'm trying to set werkzeug LocalProxy from varying tags. The best I've been able to do so far is: for tag in self.filters.iterkeys(): c = "{}_context".format(tag) setattr(self, c, ...
0
votes
2answers
46 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
51 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
24 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
36 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
1answer
41 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
37 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
54 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
65 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
29 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
61 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
55 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
30 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
46 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
82 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
65 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
45 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
73 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
50 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
60 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
74 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
46 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
70 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
28 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
92 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
78 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
47 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
71 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
45 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
88 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
65 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
78 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 ...

1 2 3 4 5 17
15 30 50 per page