| | |
Change Var. from Within a Class?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
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 |
Tag cloud for Python
abrupt ansi anti apache approximation array backend basic beginner book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary dynamic examples excel file filename float format ftp function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin port prime programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion recursive redirect refresh scrolledtext software ssh stamp statictext statistics string strings table terminal text textarea thread threading time tkinter tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame wxpython





