| | |
Change Var. from Within a Class?
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 0
Hello, I'm new to Python and I'm using Pydev. I'm having a problem: I have several classes and several variables outside the classes. I want to change a variable outside the classes from within a class:
e.g.
Basically I want to change the name variable through the class, and I'm having trouble. It's not working! Please help me! Thanks a lot!
e.g.
# Class class name_change(object): """Change a text variable outside this class""" def name_change(self): name = "elvenstruggle" # Variable name = "" # Call Class class = name_change()
Basically I want to change the name variable through the class, and I'm having trouble. It's not working! Please help me! Thanks a lot!
Last edited by elvenstruggle; Dec 21st, 2008 at 8:01 pm.
•
•
Join Date: Mar 2007
Posts: 110
Reputation:
Solved Threads: 31
Here is one way to do it:
Python Syntax (Toggle Plain Text)
>>> class test(object): ... def change_var(self, name, value): ... globals()[name] = value ... >>> var = 123 >>> obj = test() >>> obj.change_var('var', 456) >>> var 456 >>>
![]() |
Similar Threads
- PHP HTTP Screen-Scraping Class with Caching (PHP)
- Stack class, Symbol Table help (Java)
- Change the background of "active" button (JavaScript / DHTML / AJAX)
- need help: file upload using php (PHP)
- Help with Swapping Images onclick (JavaScript / DHTML / AJAX)
- make a copy of python class (Python)
- Microsoft JET Database Engine error '80040e14' (ASP)
- Mac bar (HTML and CSS)
- change statement (JSP)
Other Threads in the Python Forum
- Previous Thread: python versions
- Next Thread: python with html
| Thread Tools | Search this Thread |
address aliased anydbm app bash beginner bits calling casino changecolor cipher clear conversion coordinates corners count cturtle curves definedlines development dictionary digital dynamic events examples excel external feet file float format function gui handling hints homework iframe images import input java keycontrol line linux list lists loan loop matching mouse multiple number numbers output parsing path port prime programming projects py py2exe pygame pymailer python random rational raw_input recursion recursive scrolledtext searchingfile shebang signal singleton split string strings tails terminal text threading time tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable web-scrape whileloop word wxpython xlwt





