Search Results

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

Page 67/548 | < Previous Page | 63 64 65 66 67 68 69 70 71 72 73 74  | Next Page >

  • Partial Upload With storbinary in python

    - by brian
    I've written some python code to download an image using urllib.urlopen().read() and then upload it to an FTP site using ftplib.FTP().storbinary() but I'm having a problem. Sometimes the image file is only partially uploaded, so I get images with the bottom 20% or so cut off. I've checked the locally downloaded version and I have successfully downloaded the entire image, which leads me to believe that it is a problem with storbinary. I believe I am opening and closing all of the files correctly. Does anyone have any clues as to why I'm getting a partial upload with storbinary? Update: When I run through the commands in the Python shell, the upload completes successfully, I don't know why it would be different from when run as a script...

    Read the article

  • Learning Python coming from PHP

    - by Coronatus
    Community wiki so don't vote to close, kthxbai. My dynamic language experience is solely PHP. I want to learn Python now to broaden my career opportunities and just because I like programming. :) When learning Java, I used a site (lost the URL/real name now), something like "Java for PHP developers" that had all on one side of the page the PHP code, and on the other side the Java code to do the same thing. Is there a website like that for Python? Any other recommendations/advice? Thanks Edit: I have no votes left today, but I'll up-vote good answers tomorrow :)

    Read the article

  • Removing python and then re-installing on Mac OSX

    - by JudoWill
    I was wondering if anyone had tips on how to completely remove a python installation form Mac OSX (10.5.8) ... including virtual environments and its related binaries. Over the past few years I've completely messed up the installed site-packages, virtual-environments, etc. and the only way I can see to fix it is to just uninstall everything and re-install. I'd like to completely re-do everything and use virtualenv, pip, etc. from the beginning. On the other hand if anyone knows a way to do this without removing python and re-installing I'd be happy to here about it. Thanks, Will

    Read the article

  • Python or matplotlib limitation error

    - by Werner
    Hi, I wrote an algorithm using python and matplotlib that generates histograms from some text input data. When the number of data input is approx. greater than 15000, I get in the (append) line of my code: mydata = [] for i in range(len(data)): mydata.append(string.atof(data[i])) the error: Traceback (most recent call last): File "get_histogram_picture.py", line 25, in <module> mydata.append(string.atof(data[i])) File "/usr/lib/python2.6/string.py", line 388, in atof return _float(s) ValueError: invalid literal for float(): -a can it be an error in python ? What is the solution ? Thanks

    Read the article

  • Python: User-Defined Exception That Proves The Rule

    - by bandana
    Python documentations states: Exceptions should typically be derived from the Exception class, either directly or indirectly. the word 'typically' leaves me in an ambiguous state. consider the code: class good(Exception): pass class bad(object): pass Heaven = good() Hell = bad() >>> raise Heaven Traceback (most recent call last): File "<pyshell#163>", line 1, in <module> raise Heaven good >>> raise Hell Traceback (most recent call last): File "<pyshell#171>", line 1, in <module> raise Hell TypeError: exceptions must be classes or instances, not bad so when reading the python docs, should i change 'typically' with ''? what if i have a class hierarchy that has nothing to do with the Exception class, and i want to 'raise' objects belonging to the hierarchy? i can always raise an exception with an argument: raise Exception, Hell This seems slightly awkward to me What's so special about the Exception class, that only its family members can be raised?

    Read the article

  • Importing ctype; embedding python in C++ application

    - by Drew
    I'm trying to embed python within a C++ based programming language (CCL: The compuatational control language, not that any of you have heard of it). Thus, I don't really have a "main" function to make calls from. I have made a test .cc program with a main, and when I compile it and run it, I am able to import my own python modules and system modules for use. When I embed my code in my CCL-based program and compile it (with g++), it seems I have most functionality, but I get the import error: ImportError: /usr/lib/python2.6/lib-dynload/_ctypes.so: undefined symbol: PyType_GenericNew Can someone explain this to me and how to go about solving it? It seems like I've linked the objects correctly. Thanks.

    Read the article

  • Spawning and waiting for child processes in Python

    - by Brendan Long
    The relevant part of the code looks like this: pids = [] for size in SIZES: pids.append(os.spawnv(os.P_NOWAIT, RESIZECMD, [RESIZECMD, lotsOfOptions])) # Wait for all spawned imagemagick processes to finish while pids: (pid, status) = os.waitpid(0, 0) if pid: pids.remove(pid) What this should be doing is spawning all of the processes off, then waiting for each process to finish before continuing. What it does is work for the most part but sometimes crash on the next section (when it expects all of these processes to be finished). Is there something wrong with this? Is there a better way of doing it? The environment it has to work on is CentOS with Python 2.4, but I'm testing on Cygwin with Python 2.5, so it could be that it fails on my machine but will work on the Linux one (the Linux machine is very slow and this error is rare, so I haven't been able to get it on there).

    Read the article

  • Determine cluster size of file system in Python

    - by Philip Fourie
    I would like to calculate the "size on disk" of a file in Python. Therefore I would like to determine the cluster size of the file system where the file is stored. How do I determine the cluster size in Python? Or another built-in method that calculates the "size on disk" will also work. I looked at os.path.getsize but it returns the file size in bytes, not taking the FS's block size into consideration. I am hoping that this can be done in an OS independent way...

    Read the article

  • Python: Importing a file from a parent folder

    - by Sascha
    ...Now I know this question has been asked many times & I have looked at these other threads. Nothing so far has worked, from using sys.path.append('.') to just import foo I have a python file that wishes to import a file (that is in its parent directory). Can you help me figure out how my child file can successfully import its a file in its parent directory. I am using python 2.7 The structure is like so (each directory also has the __init__.py file in it): StockTracker/ __Comp/ ____a.py ____SubComp/ ______b.py Inside b.py, I would like to import a.py: So I have tried each of the following but I still get an error inside b.py saying "There is no such module a" import a import .a import Comp.a import StockTracker.Comp.a import os import sys sys.path.append('.') import a sys.path.remove('.')

    Read the article

  • PUT parameters not working in python / google app engine

    - by magegu
    hi, i'm working on a simple RESTful webservice with python with the webapp framework on the google app engine. Basically i'm sending all request via AJAX/jquery - for POST it works like a charm, but when I'm sending data with PUT, the parameters are empty / not processed. this is my PUT: $.ajax({ type: "PUT", url: "/boxes", data: { name: this.name, archived: this.archived }, success: function(msg){ } }); firebug saids i'm putting: Parameter application/x-www-form-urlencoded archived false name 123112323asdasd but using this python code: from google.appengine.ext import webapp from google.appengine.ext.webapp import util, template from google.appengine.ext import db from google.appengine.api.datastore_types import * from django.utils import simplejson as json import cgi import datetime class BoxHandler(webapp.RequestHandler): def post(self): #working print "test" self.response.out.write(self.request.get("name")) def put(self): print "test" #not working self.response.out.write(self.request.get("name")) will just return test Status: 200 OK Content-Type: text/html; charset=utf-8 Cache-Control: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Length: 0 so .. hm, is there anything i'm missing here? cheers, Martin

    Read the article

  • Is it possible to pickle python "units" units?

    - by Ajaxamander
    I'm using the Python "units" package (http://pypi.python.org/pypi/units/) and I've run into some trouble when trying to pickle them. I've tried to boil it down to the simplest possible to case to try and figure out what's going on. Here's my simple test: from units import unit, named_unit from units.predefined import define_units from units.compatibility import compatible from units.registry import REGISTRY a = unit('m') a_p = pickle.dumps(a) a_up = pickle.loads(a_p) logging.info(repr(unit('m'))) logging.info(repr(a)) logging.info(repr(a_up)) logging.info(a.is_si()) logging.info(a_up.is_si()) logging.info( compatible(a,a_up) ) logging.info(a(10) + a_up(10)) The output I'm seeing when I run this is: LeafUnit('m', True) LeafUnit('m', True) LeafUnit('m', True) True True False IncompatibleUnitsError I'd understand if pickling units broke them, if it weren't for the fact that repr() is returning identical results for them. What am I missing? This is using v0.04 of the units package, and Google App Engine 1.4 SDK 1

    Read the article

  • Python json memory bloat

    - by Anoop
    import json import time from itertools import count def keygen(size): for i in count(1): s = str(i) yield '0' * (size - len(s)) + str(s) def jsontest(num): keys = keygen(20) kvjson = json.dumps(dict((keys.next(), '0' * 200) for i in range(num))) kvpairs = json.loads(kvjson) del kvpairs # Not required. Just to check if it makes any difference print 'load completed' jsontest(500000) while 1: time.sleep(1) Linux top indicates that the python process holds ~450Mb of RAM after completion of 'jsontest' function. If the call to 'json.loads' is omitted then this issue is not observed. A gc.collect after this function execution does releases the memory. Looks like the memory is not held in any caches or python's internal memory allocator as explicit call to gc.collect is releasing memory. Is this happening because the threshold for garbage collection (700, 10, 10) was never reached ? I did put some code after jsontest to simulate threshold. But it didn't help.

    Read the article

  • How to synchronize threads in python?

    - by Eric
    I have two threads in python (2.7). I start them at the beginning of my program. While they execute, my program reaches the end and exits, killing both of my threads before waiting for resolution. I'm trying to figure out how to wait for both threads to finish before exiting. def connect_cam(ip, execute_lock): try: conn = TelnetConnection.TelnetClient(ip) execute_lock.acquire() ExecuteUpdate(conn, ip) execute_lock.release() except ValueError: pass execute_lock = thread.allocate_lock() thread.start_new_thread(connect_cam, ( headset_ip, execute_lock ) ) thread.start_new_thread(connect_cam, ( handcam_ip, execute_lock ) ) In .NET I would use something like WaitAll() but I haven't found the equivalent in python. In my scenario, TelnetClient is a long operation which may result in a failure after a timeout.

    Read the article

  • Is it possible to give a python dict an initial capacity (and is it usefull)

    - by Peter Smit
    I am filling a python dict with around 10,000,000 items. My understanding of dict (or hashtables) is that when too much elements get in them, the need to resize, an operation that cost quite some time. Is there a way to say to a python dict that you will be storing at least n items in it, so that it can allocate memory from the start? Or will this optimization not do any good to my running speed? (And no, I have not checked that the slowness of my small script is because of this, I actually wouldn't now how to do that. This is however something I would do in Java, set the initial capacity of the HashSet right)

    Read the article

< Previous Page | 63 64 65 66 67 68 69 70 71 72 73 74  | Next Page >