Search Results

Search found 14486 results on 580 pages for 'python idle'.

Page 49/580 | < Previous Page | 45 46 47 48 49 50 51 52 53 54 55 56  | Next Page >

  • Basic Python: Exception raising and local variable scope / binding

    - by SuperJdynamite
    I have a basic "best practices" Python question. I see that there are already StackOverflow answers tangentially related to this question but they're mired in complicated examples or involve multiple factors. Given this code: #!/usr/bin/python def test_function(): try: a = str(5) raise b = str(6) except: print b test_function() what is the best way to avoid the inevitable "UnboundLocalError: local variable 'b' referenced before assignment" that I'm going to get in the exception handler? Does python have an elegant way to handle this? If not, what about an inelegant way? In a complicated function I'd prefer to avoid testing the existence of every local variable before I, for example, printed debug information about them.

    Read the article

  • python + auto ssh proccess to get date info

    - by david
    I need to perform on my linux 5.3 ssh [Linux machine red hat 5.3] date in order to get the date results , during ssh need to answer on the following question (yes/no)? -- yes password: -- diana_123 and then I will get the date results please advice how to do this automated process with python? ( on my Linux I have Python 2.2.3 ) python script should get the IP address number , and perform automatically ssh to 103.116.140.151 and return the date results as --> Fri Nov 18 11:25:18 IST 2011 example of manual proccess: # ssh 103.116.140.151 date The authenticity of host '103.116.140.151 (103.116.140.151)' can't be established. RSA key fingerprint is ad:7e:df:9b:53:86:9f:98:17:70:2f:58:c2:5b:e2:e7. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '103.116.140.151' (RSA) to the list of known hosts. [email protected]'s password: Fri Nov 18 11:25:18 IST 2011

    Read the article

  • c style thread creation in python

    - by chandank
    Hi I am new to python and want to create multiple threads in a loop something like (in C style) for (;i < 10; i++) thread[i]= pthread_create(&thread[i],&attr,func) I am not sure how to do the same in python? Basically I want have that thread[] variable as global will create all thread at once and then will start then in once. I have written a similar python program that does it but I think having it in above style will be better. def thread_create(thread_number): command_string = "Thread-" + "%d" %thread_number thread = myThread(thread_number, command_string) thread.start() # Start new Threads for i in range(5): thread_create(i)

    Read the article

  • Problem executing with Python+MySQL

    - by Satya
    Hi, I am not getting the reason why my python script is not working though I hv put all the things correctly as my knowledge.The below test I did and it worked fine.But when I import the MySQLdb in my script it gives error as no module name MySQLdb. **C:\Python26python Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import MySQLdb ** Kindly let me know the reason for this error. And all the development is going on in windows XP, python 2.6, mysql 4.0.3 Earlier 1 hour back I have posted the question but some mistake was there in the question itself..

    Read the article

  • Python preprocessing imports

    - by FiloSottile
    I am managing a quite large python code base (2000 lines) that I want anyway to be available as a single runnable python script. So I am searching for a method or a tool to merge a development folder, made of different python files into a single running script. The thing/method I am searching for should take code split into different files, maybe with a starting __init___.py file that contains the imports and merge it into a single, big script. Much like a preprocessor. Best if a near-native way, better if I can anyway run from the dev folder. I have already checked out pypp and pypreprocessor but they don't seem to take the point. Something like a strange use of __import__() or maybe a bunch of from foo import * replaced by the preprocessor with the code? Obviously I only want to merge my directory and not common libraries.

    Read the article

  • NO able to use Xlrd module in python

    - by user1065102
    Question: i M not able to use xlrd module though i have installed the same??? Error obtained : Traceback (most recent call last): File "D:\xlrd_1.py", line 1, in import xlrd File "D:\Python31\lib\xlrd__init__.py", line 345 u"Consolidate_Area": u"\x00", ^ SyntaxError: invalid syntax Code : import xlrd print ("hi") Some more description: 1)i m using python 3.1, 2)i have installed xlrd-0.7.1.win32.exe (md5) taken from http://pypi.python.org/pypi/xlrd/0.7.1. 3)able to see the xlrd package in python\Lib\Site-packages 4)tried copying to include file also which didnt work. Need help on this..searched stackoverflow for the same problem as well as else where i didnt find answer so posting the same Appreciate for any help on the same

    Read the article

  • Using ECF shared editing with Python

    - by hekevintran
    I can use the shared editing feature of ECF with Java fine perfectly fine. When I try to do it with Python files it also works, but there is no syntax highlighting. I installed PyDev to get syntax highlighting, but then the context menu does not have the "share editor" option. I removed PyDev and the option came back. I installed Dynamic Languages Toolkit in hopes that its Python syntax highlighting was compatible and I got the same effect (context menu lacks the "share editor" option). Is there a way to have a shared editing session with Python files and syntax highlighting?

    Read the article

  • Mysterious logging.basicConfig problem (Python)

    - by Max
    I'm writing a Python script to retrieve data from Flickr. For logging purposes, I have the following setup function: def init_log(logfile): format = '%(asctime)s - %(levelname)s - %(message)s' logging.basicConfig(filename=logfile,level=logging.DEBUG,format=format) I've tested this using the python shell and it works as expected, creating a file if one doesn't already exist. But calling it from within my program is where it stops working. The function is definitely being called, and the logfile parameter is working properly – logging.basicConfig just isn't creating any file. I'm not even getting any errors or warnings. My use of the Python Flickr API may be the culprit, but I doubt it. Any ideas?

    Read the article

  • How to transition from PHP to Python Django?

    - by ggfan
    Here's my background: Decent experience with PHP/MySql. Beginner's experience with OOP Why I want to learn Python Django? I gave in, based on many searches on SO and reading over some of the answers, Python is a great, clean, and structured language to learn. And with the framework Django, it's easier to write codes that are shorter than with PHP Questions Can i do everything in Django as in PHP? Is Django a "big" hit in web development as PHP? I know Python is a great general-purpose language but I'm focused on web development and would like to know how Django ranks in terms of web development.

    Read the article

  • python - selenium script syntax error

    - by William Hawkes
    Okay, I used selenium to test some automation, which I got to work. I did an export of the script for python. When I tried to run the python script it generated, it gave me a "SyntaxError: invalid syntax" error message. Here's the python script in question: from selenium import selenium import unittest, time, re class WakeupCall(unittest.TestCase): def setUp(self): self.verificationErrors = [] self.selenium = selenium("localhost", 4444, "*chrome", "http://the.web.site") self.selenium.start() def test_wakeup_call(self): sel = self.selenium sel.open("/index.php#deposit") sel.wait_for_page_to_load("30000") sel.click("link=History") sel.wait_for_page_to_load("30000") try: self.failUnless(sel.is_text_present("key phrase number 1.")) except AssertionError, e: self.verificationErrors.append(str(e)) The last line is what generated the "SyntaxError: invalid syntax" error message. A "^" was under the comma. The rest of the script goes as follows: def tearDown(self): self.selenium.stop() self.assertEqual([], self.verificationErrors) if name == "main": unittest.main()

    Read the article

  • static effect on python

    - by fatai
    how we can construct static effect on python instead of using class and global ? not like that one : global a a = [] #simple ex ; fonk ( a , b , d) x = 1 a.append ( x) EDIT: I want to create temporary memory , if I exit the function namely fonk , I want to save change as list on temporary memory . We can do that demand only put static keyword in front of data type but in python , we dont have static, so I want that effect in python . Therefore , how can I do ? As above code say "a" represents temporary memory

    Read the article

  • Killing a subprocess including its children from python

    - by user316664
    Hi, I'm using the subprocess module on python 2.5 to spawn a java program (the selenium server, to be precise) as follows: import os import subprocess display = 0 log_file_path = "/tmp/selenium_log.txt" selenium_port = 4455 selenium_folder_path = "/wherever/selenium/lies" env = os.environ env["DISPLAY"] = ":%d.0" % display command = ["java", "-server", "-jar", 'selenium-server.jar', "-port %d" % selenium_port] log = open(log_file_path, 'a') comm = ' '.join(command) selenium_server_process = subprocess.Popen(comm, cwd=selenium_folder_path, stdout=log, stderr=log, env=env, shell=True) This process is supposed to get killed once the automated tests are finished. I'm using os.kill to do this: os.killpg(selenium_server_process.pid, signal.SIGTERM) selenium_server_process.wait() This does not work. The reason is that the shell subprocess spawns another processfor the java program, and the pid of that process is unknown to my python code. I've tried killing the process group with os.killpg, but that kills also the python process which runs this code in the first place. Setting shell to false, thus avoiding the java program to run inside a shell environment, is also out of the question, due to other reasons. Does anyone have an idea how I can kill the shell and any other processes generated by it? Cheers, Ulas

    Read the article

  • Aptana Studio is opening but not ever closing a python.exe process

    - by SC Ghost
    I am developing a small testing website using Django 1.2 in Aptana Studio build 2.0.4.1268158907. I have a Django project that I test by running the command "runserver 8001" on my project. This command runs the project on a small server that comes with Django. However the problem arises that every time I run this command Aptana opens two instances of the process "python.exe". Upon terminating the command only one of these instances is ended. The other process continues to run and use memory. My server is not online, and the process doesn't seem to do anything that I can find. This happens every time i run the runserver command on my project and therefore more and more python.exe instances will open up through my development period. Any help discovering either the purpose of this extra python.exe or a way to prevent it from opening would be much appreciated.

    Read the article

  • error in python d not defined.

    - by dtechie
    Hi I am learning python and have this error . I can figure out where\what the error is in the code. File "<string>", line 1, in <module>. Name = "" Desc = "" Gender = "" Race = "" # Prompt user for user-defined information Name = input('What is your Name? ') Desc = input('Describe yourself: ') When i run the program it outputs What is your Name? (i input d ) this gives the error Traceback (most recent call last): File "/python/chargen.py", line 19, in <module> Name = input('What is your Name? ') File "<string>", line 1, in <module> NameError: name 'd' is not defined This is an example code from Python 3 for Absolute Beginners Thank you for your help :)

    Read the article

  • Python: get windows OS version and architecture

    - by Thorfin
    First of all, I don't think this question is a duplicate of http://stackoverflow.com/questions/2208828/detect-64bit-os-windows-in-python because imho it has not been thoroughly answered. The only approaching answer is: Use sys.getwindowsversion() or the existence of PROGRAMFILES(X86) (if 'PROGRAMFILES(X86)' in os.environ) But: Can we completely rely on the windows environment variable PROGRAMFILES(X86)? I fear that anyone can create it, even if it's not present on the system. How can we use sys.getwindowsversion() to get the architecture? Regarding sys.getwindowsversion(): The link http://docs.python.org/library/sys.html#sys.getwindowsversion leads us to http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx but I don't see anything related to the architecture (32bit/64bit). Moreover, the platform element if the returned tuple seems to be independent of the architecture. One last note, I'm using python 2.5. Thanks!

    Read the article

  • Python change the working directory for an exe opened with startfile

    - by Saulpila
    In python i'm using the os.startfile command to start a windows executable that does especific stuff in its own folder, the python code is running from another folder, so when I start the file, it starts in the python script's working directory, but it has to start in its own directory. I've tried to use os.chdir(path) to change the working directory, but it fails, the file still not runs in it's own folder. I thought maybe there is a command like shortcut's "Start in" line. I've searched everywere, but not success. The only solution comes to my mind is to create a shortcut and add the "start in" line, then launch the shortcut, but that is very impractical.

    Read the article

  • Python to C# Conversion of RGBA values not working

    - by clangers
    I'm currently converting some python code to C#, and I'm having an issue with the RGBA C# libraries # Original Python Code: d = math.sqrt( (x - size/2.0)**2 + (y - size/2.0)**2 ) rgbVal = int(200*d/md + 50) rgba = (0,0,0, 255 - rgbVal) img.putpixel((x,y), rgba) // My C# Code double d = Math.Sqrt(Math.Pow((x - DotSize / 2.0), 2) + Math.Pow((y - DotSize / 2.0), 2)); int rgbVal = (int) (200 * d / md + 50); Color color = Color.FromArgb(255 - rgbVal, 0, 0, 0); // ** ERROR ** img.SetPixel(x,y, color); At both instances of the code d is equal to 106 and md is equal to 53. However the resulting rgbVal value is 450. This would obviously mean that 255 - 450 is -195, which causes an error to be thrown as each individual value must be between 0 and 255. Anyone have any idea how I can fix this. Please note that the data is the same when running both the python and C# versions.

    Read the article

  • setfsuid() and python 2.5.4

    - by user331398
    Hi, I'm trying to use setfsuid() with python 2.5.4 and RHEL 5.4. Since it's not included in the os module, I wrapped it in a C module of my own and installed it as a python extension module using distutils. However when I try to use it I don't get the expected result. setfsuid() returns value indicating success (changing from a superuser), but I can't access files to which only the newly set user should have user access (using open()), indicating that fsuid was not truely changed. I tried to verify setfsuid() worked, by running it consecutively twice with the same user input The result was as if nothing had changed, and on every call the returned value was of old user id different from the new one. I also called getpid() from the module, and from the python script, both returned the same id. so this is not the problem. Just in case it's significant, I should note that I'm doing all of this from within an Apache daemon process (WSGI). Anyone can provide an explanation to that? Thank you

    Read the article

  • Switching from php to python

    - by ts
    Hello I am trying to make a list of things which can be difficult/surprising to someone who is changing language from PHP to Python. so far i have rather short list: forget require / include, learn import (this was most difficult to me - to understand package - module - class - object hierarchy and its mapping to filesystem) you can't just upload file on server to have webpage (-mod_python, wsgi etc) learn the python way for use variable class names (new $class() vs import + getattr) / operator in python 2.x and all float-related horrors those were difficult to me, it takes few days before mind adapts a new paradigm after i found that there is few other areas which could be challenging for someone with (too) many years of php: everything is an object you have to live with exceptions array vs list, set, dictionary, tuple ... learn (effective) list comprehensions learn generators any other ideas / personal experiences ?

    Read the article

  • Make a simulation using python

    - by user3727759
    I am new to programming and using python. What I am trying to do is create a simulation of a thermostat system by using python. Is there a way to create a program that I can input data, for example temperature and humidity values and then have python constantly plotting the data as I enter the values. This is to simulate a device gathering data and sending it to this program and having it being plotted. I have found ways to plot data by using matplotlib but I have not been able to find a way that I can input the data and have the plot upgrade constantly. Thanks any advise is appreciated.

    Read the article

  • How do I force apt-get to install a package that will not install due to a bug introduced by Ubuntu 11.10?

    - by Hemm
    Ubuntu 11.10 separated out python-profiler from the Python standard library due to licensing philosophies. (According to what I could Google, correct me if I'm wrong.) This is an active bug since October for 11.10. I have Python 2.7.2 installed, so the dependency errors are wrong. 'apt-get check' does not resolve the problem. What is the best way to resolve to this? Thank you. sudo apt-get install python-profiler Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: python-profiler : Depends: python (>= 2.5) but it is not going to be installed Depends: python (< 2.8) but it is not going to be installed E: Unable to correct problems, you have held broken packages.

    Read the article

  • Need help with yum,python and php in CentOS. (I made a complete mess!)

    - by pek
    Hello, a while back I wanted to install some plugins for Trac but it required python 2.5 I tried installing it (I don't remember how) and the only thing I managed was to have two versions of python (2.4 and 2.5). Trac still uses the old version but the console uses 2.5 (python -V = Python 2.5.2). Anyway, the problem is not python, the problem is yum (which uses python). I am trying to upgrade my PHP version from 5.1.x to 5.2.x. I tried following this tutorial but when I reach the step with yum I get this error: [root@XXX]# yum update Loading "installonlyn" plugin Setting up Update Process Setting up repositories Reading repository metadata in from local files Traceback (most recent call last): File "/usr/bin/yum", line 29, in ? yummain.main(sys.argv[1:]) File "/usr/share/yum-cli/yummain.py", line 94, in main result, resultmsgs = base.doCommands() File "/usr/share/yum-cli/cli.py", line 381, in doCommands return self.yum_cli_commands[self.basecmd].doCommand(self, self.basecmd, self.extcmds) File "/usr/share/yum-cli/yumcommands.py", line 150, in doCommand return base.updatePkgs(extcmds) File "/usr/share/yum-cli/cli.py", line 672, in updatePkgs self.doRepoSetup() File "/usr/share/yum-cli/cli.py", line 109, in doRepoSetup self.doSackSetup(thisrepo=thisrepo) File "/usr/lib/python2.4/site-packages/yum/init.py", line 338, in doSackSetup self.repos.populateSack(which=repos) File "/usr/lib/python2.4/site-packages/yum/repos.py", line 200, in populateSack sack.populate(repo, with, callback, cacheonly) File "/usr/lib/python2.4/site-packages/yum/yumRepo.py", line 91, in populate dobj = repo.cacheHandler.getPrimary(xml, csum) File "/usr/lib/python2.4/site-packages/yum/sqlitecache.py", line 100, in getPrimary return self._getbase(location, checksum, 'primary') File "/usr/lib/python2.4/site-packages/yum/sqlitecache.py", line 86, in _getbase (db, dbchecksum) = self.getDatabase(location, metadatatype) File "/usr/lib/python2.4/site-packages/yum/sqlitecache.py", line 82, in getDatabase db = self.makeSqliteCacheFile(filename,cachetype) File "/usr/lib/python2.4/site-packages/yum/sqlitecache.py", line 245, in makeSqliteCacheFile self.createTablesPrimary(db) File "/usr/lib/python2.4/site-packages/yum/sqlitecache.py", line 165, in createTablesPrimary cur.execute(q) File "/usr/lib/python2.4/site-packages/sqlite/main.py", line 244, in execute self.rs = self.con.db.execute(SQL) _sqlite.DatabaseError: near "release": syntax error Any help? Thank you.

    Read the article

  • How do I install MySQLdb on a Python 2.6 source build, on Debian Lenny?

    - by nbolton
    I've installed Python 2.6 from source on my Debian Lenny server, as Lenny does not have the python2.6 package. So, my Python 2.5 has MySQLdb installed and working just fine because I installed the python-mysqldb package. I figured I could just install MySQLdb from source, but because I have the Lenny python-dev package, it builds against 2.5: # python setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.5/MySQLdb running build_ext building '_mysql' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.5 -c _mysql.c -o build/temp.linux-x86_64-2.5/_mysql.o -DBIG_JOINS=1 -fPIC gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.5/_mysql.o -L/usr/lib/mysql -lmysqlclient_r -o build/lib.linux-x86_64-2.5/_mysql.so I don't want to run python setup.py install, because I'm afraid it's going to screw up MySQLdb on 2.5 -- should I? I imagine it'd just overwrite 2.5 and do nothing to 2.6 -- maybe there's an argument I can use to install to 2.6? I imagine that I would need also to build against 2.6, so how do I do this?

    Read the article

  • Accessing Python module fails although its package is imported

    - by codethief
    Hey Stackers! :) My Django project's directory hierarchy looks like this: + pybsd |---+ devices |---+ templates |---+ views |---+ interaction |---- __init__.py |---- geraete.py |---- geraetemodelle.py |---- geraetegruppen.py |---- __init__.py |---- ajax.py |---- html.py |---- misc.py |---- __init__.py |---- urls.py |---- __init__.py |---- urls.py (Please excuse the German names. I preferred not to replace them here since it would add yet another possible error source when trying out the solutions you'll hopefully suggest and answering your questions.) Every request to http://URL/devices/.* is dispatched to the urls.py file living in /devices: # ... from views import html, ajax, misc, interaction urlpatterns = patterns('', # ... (r'^ajax/update/(?P<table>[a-z_]+)$', ajax.update), (r'^ajax/delete/(?P<table>[a-z_]+)$', ajax.delete), (r'^ajax/select_options/(?P<table>[a-z_]+)$', ajax.select_options), (r'^interaction/geraete/info/(?P<geraet>\d+)$', interaction.geraete.info), (r'^interaction/geraete/delete/(?P<geraet>\d+)?$', interaction.geraete.delete), (r'^interaction/geraetemodelle/delete/(?P<geraetemodell>\d+)?$', interaction.geraetemodelle.delete), (r'^interaction/geraetegruppen/delete/(?P<geraetegruppe>\d+)?$', interaction.geraetegruppen.delete), # ... ) All URL definitions work except for those referencing the interaction package. I'm constantly getting the following error: File "/home/simon/projekte/pybsd/../pybsd/devices/urls.py", line 33, in `<module>` (r'^interaction/geraete/info/(?P<geraet>\d+)$', interaction.geraete.info), AttributeError: 'module' object has no attribute 'geraete' I double-checked that the __init__.py files don't contain anything. Maybe you've already found the (Python- or Django-related?) mistake I made and am apparently unable to see. If not, read on. In any case, thanks for reading this long post! Isolating the problem 1st test It works if I provide the view functions as strings: (r'^interaction/geraete/info/(?P<geraet>\d+)$', 'devices.views.interaction.geraete.info'), (r'^interaction/geraete/delete/(?P<geraet>\d+)?$', 'devices.views.interaction.geraete.delete'), (r'^interaction/geraetemodelle/delete/(?P<geraetemodell>\d+)?$', 'devices.views.interaction.geraetemodelle.delete'), (r'^interaction/geraetegruppen/delete/(?P<geraetegruppe>\d+)?$', 'devices.views.interaction.geraetegruppen.delete'), ... or add yet another line to the imports: from views.interaction import geraete, geraetemodelle, geraetegruppen Using from views.interaction import *, however, doesn't work either and results in the same error message. 2nd test I created a file test.py in /devices: from views import interaction print dir(interaction) Output: simon@bsd-simon:~/projekte/pybsd/devices$ python test.py ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] Again, no sign of the modules I created in the interaction package (geraete.py, geraetemodelle.py, geraetegruppen.py). Unlike in urls.py, trying from view.interaction import geraete, geraetegruppen, geraetemodelle in test.py results in ImportError: No module named view.interaction this time. 3rd test I started the Django shell: $ python manage.py shell >>> import devices.views.interaction.geraete >>> dir(devices.views.interaction.geraete) ['Abteilung', 'Auftrag', 'Auftragsvorlage', 'Geraet', 'Geraetegruppe', 'Geraetemodell', 'HttpResponse', 'HttpResponseBadRequest', 'HttpResponseRedirect', 'Raum', 'Standort', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'delete', 'info', 'models', 'move', 'render_to_response'] >>> $ python manage.py shell >>> from devices.views.interaction import geraete >>> dir(geraete) ['Abteilung', 'Auftrag', 'Auftragsvorlage', 'Geraet', 'Geraetegruppe', 'Geraetemodell', 'HttpResponse', 'HttpResponseBadRequest', 'HttpResponseRedirect', 'Raum', 'Standort', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'delete', 'info', 'models', 'move', 'render_to_response'] >>> $ python manage.py shell >>> import devices.views.interaction >>> devices.views.interaction.geraete Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'module' object has no attribute 'geraete' >>> dir(devices.views.interaction) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

    Read the article

  • python-imaging and libjpeg on FreeBSD

    - by valya
    Hello! I had a problem with image uploading to Django with FreeBSD, so I asked on SO: http://stackoverflow.com/questions/1959447/django-uploading-image-error and got an answer. Our admin can't install these libraries, he don't know how. Neither do I. It's FreeBSD, kinda unfamiliar system. So, how do we install PIL with JPEG support and whatever needed for image uploading?

    Read the article

< Previous Page | 45 46 47 48 49 50 51 52 53 54 55 56  | Next Page >