Search Results

Search found 13693 results on 548 pages for 'python metaprogramming'.

Page 115/548 | < Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >

  • python input UnicodeDecodeError:

    - by The man on the Clapham omnibus
    python 3.x >>> a = input() hope >>> a 'hope' >>> b = input() håpe >>> b 'håpe' >>> c = input() start typing hå... delete using backspace... and change to hope Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'utf8' codec can't decode byte 0xc3 in position 1: invalid continuation byte >>> The situation is not terrible, I am working around it, but find it strange that when deleting, the bytes get messed up. Has anyone else experienced this? the terminal history shows that I thought that I entered h?ope any ideas? in the script that is using this, I do import readline to give command line history.

    Read the article

  • How to display and change an icon inside a python Tk Frame

    - by codingJoe
    I have a python Tkinter Frame that displays several fields. I want to also add an red/yellow/green icon that will display the status of an external device. The icon is loaded from a file called ICON_LED_RED.ico. How do I display the icon in my frame? How do I change the icon at runtime? for example replace BitmapImage('RED.ico') with BitmapImage('GREEN.ico') class Application(Frame): def init(self, master=None): Frame.__init__(self, master) self.pack() self.createWidgets() def createWidgets(self): # ...other frame code.. works just fine. self.OKBTN = Button(self) self.OKBTN["text"] = "OK" self.OKBTN["fg"] = "red" self.OKBTN["command"] = self.ok_btn_func self.OKBTN.pack({"side": "left"}) # when I add the following the frame window is not visible # The process is locked up such that I have to do a kill -9 self.statusFrame = Frame(self, bd=2, relief=RIDGE) Label(self.statusFrame, text='Status:').pack(side=LEFT, padx=5) self.statIcon = BitmapImage('data/ICON_LED_RED.ico') Label (self.statusFrame, image=self.statIcon ).grid() self.statusFrame.pack(expand=1, fill=X, pady=10, padx=5)

    Read the article

  • How to connect to foreign DB2 database using Python (Ubuntu)

    - by dblips
    sudo easy_install ibm_db-1.0.1-py2.5-linux-i686.egg only works after sudo apt-get install python-dev. Some troubles to find that out in the first place ... Downloaded from IBM site v9.5fp5_linuxia32_dsdriver.tar.gz and pointing IBM_DB_DIR and IBM_DB_LIB to the clidriver(/lib) dir -- is this needed/correct one? -- libdb2.so(.1) is in there... Nevertheless: >>> import ibm_db Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: libdb2.so.1: cannot open shared object file: No such file or directory Any help is very much appreciated!

    Read the article

  • C# style properties in python

    - by 3D-Grabber
    I am looking for a way to define properties in Python similar to C#, with nested get/set definitions. This is how far I got: #### definition #### def Prop(fcn): f = fcn() return property(f['get'], f['set']) #### test #### class Example(object): @Prop def myattr(): def get(self): return self._value def set(self, value): self._value = value return locals() # <- how to get rid of this? e = Example() e.myattr = 'somevalue' print e.myattr The problem with this is, that it still needs the definition to 'return locals()'. Is there a way to get rid of it? Maybe with a nested decorator?

    Read the article

  • Python unittest with expensive setup

    - by Staale
    My test file is basically: class Test(unittest.TestCase): def testOk(): pass if __name__ == "__main__": expensiveSetup() try: unittest.main() finally: cleanUp() However, I do wish to run my test through Netbeans testing tools, and to do that I need unittests that don't rely on an environment setup done in main. Looking at http://stackoverflow.com/questions/402483/caching-result-of-setup-using-python-unittest - it recommends using Nose. However, I don't think Netbeans supports this. I didn't find any information indicating that it does. Additionally, I am the only one here actually writing tests, so I don't want to introduce additional dependencies for the other 2 developers unless they are needed. How can I do the setup and cleanup once for all the tests in my TestSuite? The expensive setup here is creating some files with dummy data, as well as setting up and tearing down a simple xml-rpc server. I also have 2 test classes, one testing locally and one testing all methods over xml-rpc.

    Read the article

  • How to add a custom loglevel to Python's logging facility

    - by tuergeist
    Hi, I'd like to have loglevel TRACE (5) for my application as I don't think that debug() is enought. Additionally log(5, msg) isn't what I want. The question is, how can I add a custom log level to a Python logger? Actually I've a mylogger.py with the following content: import logging @property def log(obj): myLogger = logging.getLogger(obj.__class__.__name__) return myLogger In my code I use it in the following way: class ExampleClass(object): from mylogger import log def __init__(self): '''The constructor with the logger''' self.log.debug("Init runs") Now I'd like to call self.log.trace("foo bar") Thanks in advance for your help.

    Read the article

  • AUTOMATING EXCEL MACRO USING PYTHON

    - by user324056
    Hi all, Here is my question... I am using python in Linux to automate an excel. I have finished writing data into excel by using pyexcelerator package. Now comes the real challenge. I have to add another tab to the existing sheet and that tab should contain the macro run in the first tab. All these things should be automated. I googled a lot and found win32come to do a job in macro, but that was only for windows. Anyone have any idea of how to do this, or can you guide me with few suggestions. Thanks in advance.

    Read the article

  • Python .app doesn't read .txt file like it should

    - by Bambo
    This question relates to this one: Python app which reads and writes into its current working directory as a .app/exe i got the path to the .txt file fine however now when i try to open it and read the contents it seems that it doesn't extract the data properly. Here's my code - http://pastie.org/4876896 These are the errors i'm getting: 30/09/2012 10:28:49.103 [0x0-0x4e04e].org.pythonmac.unspecified.main: for index, item in enumerate( lines ): # iterate through lines 30/09/2012 10:28:49.103 [0x0-0x4e04e].org.pythonmac.unspecified.main: TypeError: 'NoneType' object is not iterable I kind of understand what the errors mean however i'm not sure why they are being flagged up because if i run my script with it not in a .app form it doesn't get these errors and extracts the data fine.

    Read the article

  • Beginner questions regarding Python classes.

    - by Andy
    Hi. I am new to Python so please don't flame me if I ask something too noobish :) 1. Consider I have a class: class Test: def __init__(self, x, y): self.x = x self.y = y def wow(): print 5 * 5 Now I try to create an object of the class: x = Test(3, 4) This works as expected. However, when I try to call the method wow(), it returns an error, which is fixed by changing wow() to: def wow(self) Why do I need to include self and if I don't, what does the method mean?2. In the definition of __init__: def __init__(self, x, y): self.x = x self.y = y Why do I need to declare x and y, when I can do this: def __init__(self): self.x = x self.y = y I hope I am being clear... Thanks for your time.

    Read the article

  • python - returns incorrect positive #

    - by tekknolagi
    what i'm trying to do is write a quadratic equation solver but when the solution should be -1, as in quadratic(2, 4, 2) it returns 1 what am i doing wrong? #!/usr/bin/python import math def quadratic(a, b, c): #a = raw_input("What\'s your `a` value?\t") #b = raw_input("What\'s your `b` value?\t") #c = raw_input("What\'s your `c` value?\t") a, b, c = float(a), float(b), float(c) disc = (b*b)-(4*a*c) print "Discriminant is:\n" + str(disc) if disc = 0: root = math.sqrt(disc) top1 = b + root top2 = b - root sol1 = top1/(2*a) sol2 = top2/(2*a) if sol1 != sol2: print "Solution 1:\n" + str(sol1) + "\nSolution 2:\n" + str(sol2) if sol1 == sol2: print "One solution:\n" + str(sol1) else: print "No solution!" EDIT: it returns the following... import mathmodules mathmodules.quadratic(2, 4, 2) Discriminant is: 0.0 One solution: 1.0

    Read the article

  • IDLE wont start Python 2.6.5

    - by anteater7171
    I was using it as my primary text editor for quite sometime. However, one day it just stopped working. This had happened to me several times before, so I simply tried to end all procceses using windows task manager. However that didn't work. I've recently tried getting it to work again. Whenever I try to reopen it it informs me that it's subprocess couldn't connect. I tried uninstalling it and reinstalling it, yet the problem persists. Anyone have any other solutions? Important facts: Windows 7, Python 2.6.5

    Read the article

  • stuck in while loop python

    - by user1717330
    I am creating a chat server in python and got quite far as a noob in the language. I am having 1 problem at the moment which I want to solve before I go further, but I cannot seem to find how to get the problem solved. It is about a while loop that continues.. in the below code is where it goes wrong while 1: try: data = self.channel.recv ( 1024 ) print "Message from client: ", data if "exit" in data: self.channel.send("You have closed youre connection.\n") break except KeyboardInterrupt: break except: raise When this piece of code get executed, on my client I need to enter "exit" to quit the connection. This works as a charm, but when I use CTRL+C to exit the connection, my server prints "Message from client: " a couple of thousand times. where am I going wrong?

    Read the article

  • Identifying a function call in a python script line in runtime

    - by Dani
    I have a python script that I run with 'exec'. The script's string has calls to functions. When a function is called, I would like it to know the line number and offset in line for that call in the script (in the string I fed exec with). Here is an example. If my script is: foo1(); foo2(); foo1() foo3() And if I have code that prints (line,offset) in every function, I should get (0,0), (0,8), (0,16), (1,0) In most cases this can be easily done by getting the stack frame, because it contains the line number and the function name. The only problem is when there are two functions with the same name in a certain line. Unfortunately this is a common case for me. Any ideas?

    Read the article

  • list python package dependencies without loading them ?

    - by Denis
    Say that python package A requires B, C and D; is there a way to list A → B C D without loading them ? Requires in the metadata (yolk -M A) are often incomplete, grr. One can download A.tar / A.egg, then look through A/setup.py, but some of those are pretty gory. (I'd have thought that getting at least first-level dependencies could be mechanized; even a 98 % solution would be better than avalanching downloads.) A related question: pip-upgrade-package-without-upgrading-dependencies

    Read the article

  • Python Textwrap - forcing 'hard' breaks

    - by Tom Werner
    I am trying to use textwrap to format an import file that is quite particular in how it is formatted. Basically, it is as follows (line length shortened for simplicity): abcdef <- Ok line abcdef ghijk <- Note leading space to indicate wrapped line lm Now, I have got code to work as follows: wrapper = TextWrapper(width=80, subsequent_indent=' ', break_long_words=True, break_on_hyphens=False) for l in lines: wrapline=wrapper.wrap(l) This works nearly perfectly, however, the text wrapping code doesn't do a hard break at the 80 character mark, it tries to be smart and break on a space (at approx 20 chars in). I have got round this by replacing all spaces in the string list with a unique character (#), wrapping them and then removing the character, but surely there must be a cleaner way? N.B Any possible answers need to work on Python 2.4 - sorry!

    Read the article

  • python len calculation

    - by n00bz0r
    I'm currently trying to build a RDP client in python and I came across the following issue with a len check; From: http://msdn.microsoft.com/en-us/library/cc240836%28v=prot.10%29.aspx "81 2a - ConnectData::connectPDU length = 298 bytes Since the most significant bit of the first byte (0x81) is set to 1 and the following bit is set to 0, the length is given by the low six bits of the first byte and the second byte. Hence, the value is 0x12a, which is 298 bytes." This sounds weird. For normal len checks, I'm simply using : struct.pack("h",len(str(PacketLen))) but in this case, I really don't see how I can calculate the len as described above. Any help on this would be greatly appreciated !

    Read the article

  • Python Class inherit from all submodules

    - by Dhruv Govil
    I'm currently writing a wrapper in python for a lot of custom company tools. I'm basically going to break each tool into its own py file with a class containing the call to the tool as a method. These will all be contained in a package. Then there'll be a master class that will import all from the package, then inherit from each and every class, so as to appear as one cohesive class. masterClass.py pyPackage - __ init__.py - module1.py --class Module1 ---method tool1 - module2.py --class Module2 ---method tool2 etc Right now, I'm autogenerating the master class file to inherit from the packages modules, but I was wondering if there was a more elegant way to do it? ie from package import * class MasterClass(package.all): pass

    Read the article

  • Python: confused with classes, attributes and methods in OOP

    - by user1586038
    A. Am learning Python OOP now and confused with somethings in the code below. Question: 1. def init(self, radius=1): What does the argument/attribute "radius = 1" mean exactly? Why isn't it just called "radius"? The method area() has no argument/attribute "radius". Where does it get its "radius" from in the code? How does it know that the radius is 5? """ class Circle: pi = 3.141592 def __init__(self, radius=1): self.radius = radius def area(self): return self.radius * self.radius * Circle.pi def setRadius(self, radius): self.radius = radius def getRadius(self): return self.radius c = Circle() c.setRadius(5) """ B. Question: In the code below, why is the attribute/argument "name" missing in the brackets? Why was is not written like this: def init(self, name) and def getName(self, name)? """ class Methods: def init(self): self.name = 'Methods' def getName(self): return self.name """

    Read the article

  • How to grab the lines AFTER a matched line in python

    - by toofly
    Hi All, I am an amateur using Python on and off for some time now. Sorry if this is a silly question, but I was wondering if anyone knew an easy way to grab a bunch of lines if the format in the input file is like this: " Heading 1 Line 1 Line 2 Line 3 Heading 2 Line 1 Line 2 Line 3 " I won't know how many lines are after each heading, but I want to grab them all. All I know is the name, or a regular expression pattern for the heading. The only way I know to read a file is the "for line in file:" way, but I don't know how to grab the lines AFTER the line I'm currently on. Hope this makes sense, and thanks for the help!

    Read the article

  • Python ctypes: loading DLL from from a relative path

    - by Frederick
    I have a Python module, wrapper.py, that wraps a C DLL. The DLL lies in the same folder as the module. Therefore, I use the following code to load it: myDll = ctypes.CDLL("MyCDLL.dll") This works if I execute wrapper.py from its own folder. If, however, I run it from elsewhere, ctypes goes looking for DLL in the current working directory and naturally fails. My question is, is there a way by which I can specify the DLL's path relative to the wrapper instead of the current working directory? This will enable me to ship the two together and allow the user to run/import the wrapper from anywhere.

    Read the article

  • python: naming a module that has a two-word name

    - by Jason S
    I'm trying to put together a really simple module with one .py source file in it, and have already run into a roadblock. I was going to call it scons-config but import scons-config doesn't work in Python. I found this SO question and looked at PEP8 style guide but am kind of bewildered, it doesn't talk about two-word-name conventions. What's the right way to deal with this? module name: SconsConfig? scons_config? sconsconfig? scons.config? name of the single .py file in it: scons-config.py? scons_config.py?

    Read the article

  • Python Etiquette: Importing Modules

    - by F3AR3DLEGEND
    Say I have two Python modules: module1.py: import module2 def myFunct(): print "called from module1" module2.py: def myFunct(): print "called from module2" def someFunct(): print "also called from module2" If I import module1, is it better etiquette to re-import module2, or just refer to it as module1.module2? For example (someotherfile.py): import module1 module1.myFunct() # prints "called from module1" module1.module2.myFunct() # prints "called from module2" I can also do this: module2 = module1.module2. Now, I can directly call module2.myFunct(). However, I can change module1.py to: from module2 import * def myFunct(): print "called from module1" Now, in someotherfile.py, I can do this: import module1 module1.myFunct() # prints "called from module1"; overrides module2 module1.someFunct() # prints "also called from module2" Also, by importing *, help('module1') shows all of the functions from module2. On the other hand, (assuming module1.py uses import module2), I can do: someotherfile.py: import module1, module2 module1.myFunct() # prints "called from module1" module2.myFunct() # prints "called from module2" Again, which is better etiquette and practice? To import module2 again, or to just refer to module1's importation?

    Read the article

  • Python BeautifulSoup Print Info in CSV

    - by Codin
    I can print the information I am pulling from a site with no problem. But when I try to place the street names in one column and the zipcodes into another column into a CSV file that is when I run into problems. All I get in the CSV is the two column names and every thing in its own column across the page. Here is my code. Also I am using Python 2.7.5 and Beautiful soup 4 from bs4 import BeautifulSoup import csv import urllib2 url="http://www.conakat.com/states/ohio/cities/defiance/road_maps/" page=urllib2.urlopen(url) soup = BeautifulSoup(page.read()) f = csv.writer(open("Defiance Steets1.csv", "w")) f.writerow(["Name", "ZipCodes"]) # Write column headers as the first line links = soup.find_all(['i','a']) for link in links: names = link.contents[0] print unicode(names) f.writerow(names)

    Read the article

  • using special characters in functions: Python

    - by satyajit
    I am writing an xmlrpc client which uses a server written in ruby. One of the functions is framework.busy?(). Let me show the ruby version: server.call( "framework.busy?" ) So lets assume I create an instance of the ServerProxy class say server. So while using python to call the function busy? I need to use: server.framework.busy?() This leads to an error: SyntaxError: invalid syntax How can I call this function? Or am I reading the ruby code wrong and implementing it wrongly.

    Read the article

  • Multiple python scripts sending messages to a single central script

    - by Ipsquiggle
    I have a number of scripts written in Python 2.6 that can be run arbitrarily. I would like to have a single central script that collects the output and displays it in a single log. Ideally it would satisfy these requirements: Every script sends its messages to the same "receiver" for display. If the receiver is not running when the first script tries to send a message, it is started. The receiver can also be launched and ended manually. (Though if ended, it will restart if another script tries to send a message.) The scripts can be run in any order, even simultaneously. Runs on Windows. Multiplatform is better, but at least it needs to work on Windows. I've come across some hints: os.pipe() multiprocess Occupying a port mutex From those pieces, I think I could cobble something together. Just wondering if there is an obviously 'right' way of doing this, or if I could learn from anyone's mistakes.

    Read the article

< Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >