| | |
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
advanced aliased bash beginner bits calling casino changecolor class clear code command convert corners count csv cturtle cursor definedlines dictionary digital dynamic dynamically events examples excel external file float format frange function gui hints homework i/o iframe import info input java line linux list lists loop matching mouse multiple number numbers obexftp output panel parsing path port prime programming projects py py-mailer py2exe pygame pyqt python random rational raw_input recursion return scrolledtext signal singleton stderr string strings subprocess table tails terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 valueerror variable web-scrape whileloop windows word wxpython





