| | |
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 |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog data decimals dictionaries dictionary drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyqt python random recursion schedule script scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib





