Q_CreationDate
stringlengths
23
23
Title
stringlengths
11
149
Question
stringlengths
25
6.53k
Answer
stringlengths
15
5.1k
Score
float64
-1
1.2
Is_accepted
bool
2 classes
N_answers
int64
1
17
Q_Id
int64
0
6.76k
2012-10-06 16:24:55.323
Full Hexadecimal Representation in Python?
I've writing a RSA implementation in Python and have now successfully encrypted it however when it prints out the cipher, every time it comes out '0x1L.' I believe this is a long number, however I do not know how to show the full number. If my code is required, I will post in the comments section( It is quite long). T...
Python's representation of your result as 0x1L indicates the number's type and value - however, it doesn't truncate the number at all. While it is stored as a long internally, its value is still just 1 in this case.
1.2
true
1
2,146
2012-10-06 20:31:45.100
User profiling for topic-based recommender system
I'm trying to come up with a topic-based recommender system to suggest relevant text documents to users. I trained a latent semantic indexing model, using gensim, on the wikipedia corpus. This lets me easily transform documents into the LSI topic distributions. My idea now is to represent users the same way. However, o...
"represent a user as the aggregation of all the documents viewed" : that might work indeed, given that you are in linear spaces. You can easily add all the documents vectors in one big vector. If you want to add the ratings, you could simply put a coefficient in the sum. Say you group all documents rated 2 in a vector ...
0
false
2
2,147
2012-10-06 20:31:45.100
User profiling for topic-based recommender system
I'm trying to come up with a topic-based recommender system to suggest relevant text documents to users. I trained a latent semantic indexing model, using gensim, on the wikipedia corpus. This lets me easily transform documents into the LSI topic distributions. My idea now is to represent users the same way. However, o...
I don't think that's working with lsa. But you maybe could do some sort of k-NN classification, where each user's coordinates are the documents viewed. Each object (=user) sends out radiation (intensity is inversely proportional to the square of the distance). The intensity is calculated from the ratings on the single...
0.201295
false
2
2,147
2012-10-08 05:34:48.387
Django - How does order_by work?
I'd like to know how Django's order_by works if the given order_by field's values are same for a set of records. Consider I have a score field in DB and I'm filtering the queryset using order_by('score'). How will records having the same values for score arrange themselves? Every time, they're ordered randomly within ...
order_by can have multiple params, I think order_by('score', '-create_time') will always return the same queryset.
1.2
true
1
2,148
2012-10-08 20:40:57.347
Hidden file attributes
In Python, how do you make a particular file hidden? Or how do you set the file attribute as 'hidden' without using external API's/modules such as WIN32API, etc. Surely there is something in the standard libraries? As the os module does allow to set the "read" and 'write' attributes, it is very strange that there is no...
Not all operating systems have the concept of "hidden" for files, and most (even with all the different versions of Windows 7 etc. there are still more forms of *nix out there than Windows) indicate it by having the first character of the filename be a period (.). On the OSes that do support it you must use some extern...
0.386912
false
1
2,149
2012-10-09 10:26:43.480
For what purpose Django is used for?
I heard a lot of people talking about Django on various forums. But I am having a very basic question : What is meant by Framework and why Django is used. After listening a lot about Django, I ran few chapters for Django (from Djangobook.com). After running these chapters, I am wondering how Django can be used to crea...
No. It's not for making websites. Your sample just sounds like you want plain old HTML. Django is for creating web applications. That is, software, normally backed by a database, that includes some kind of interactivity, that operates through a browser. A Framework provides a structure and common methods for making th...
1.2
true
1
2,150
2012-10-10 11:35:51.147
How to make GtkMenuToolButton open the same menu when 'clicked' signal is emitted?
I am using GtkMenuToolButton and it has a button and a menu. When you click on the arrow the menu is opened. I'd like to make the button open that same menu as well. Simply emitting "show-menu" in the "clicked" callback did not work. Please help how to make this work.
I have currently ended up doing this: Instead of GtkMenuToolButton I have GtkToolItem with custom content In custom content I have GtkMenuButton Inside that one, I delete the default GtkArrow and replace it with 1x2 GtkGrid which has a Label + GtkArrow As a whole it does what I want =)
0.201295
false
1
2,151
2012-10-10 14:01:08.920
What are ngram counts and how to implement using nltk?
I've read a paper that uses ngram counts as feature for a classifier, and I was wondering what this exactly means. Example text: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam" I can create unigrams, bigrams, trigrams, etc. out of this text, where I have to define on which "level" to create these un...
I don't think there is a specific method in nltk to help with this. This isn't tough though. If you have a sentence of n words (assuming you're using word level), get all ngrams of length 1-n, iterate through each of those ngrams and make them keys in an associative array, with the value being the count. Shouldn't be m...
-0.101688
false
1
2,152
2012-10-11 08:20:45.397
What are the use cases for Python's __new__?
I understand what __new__ does (and how it's different from __init__) so I'm not interested in definitions, I'm interested in when and how to use __new__. The documentation says: In general, you shouldn't need to override __new__ unless you're subclassing an immutable type like str, int, unicode or tuple But I can't ...
A potential use case could be a "factory class" which returns instances of various classes depending on the implementation.
0.386912
false
1
2,153
2012-10-11 13:29:36.447
Enable Monetization on YouTube video using YouTube API
I am uploading videos to YouTube by using YouTube Data API (Python client library). Is it possible to set monetizing for that video from API rather than going to my account on the YouTube website and manually setting monetization for that uploaded video? If yes, then how can I do it from API? I am unable to find it in ...
That's not something that's supported as part of the public YouTube Data API.
0.673066
false
1
2,154
2012-10-11 21:19:31.877
Python structural issue: Giving an 'engine' class to everything
I am having some issues making 'bigger than simple scripts and stuff' applications in Python. I have a class called WinMain, a class called Engine, one called State and another called Element. It's laid out like this: WinMain is the main class of the program, it has a mainLoop function and various other things. Engine...
Engine is an object that contains data like images and rendering code This sounds like a God class: they're common in GUI code, and the problem you're having is a common effect of that. What is the conceptual relationship between different stuff in Engine? Does it need to be tightly coupled, or could the Engine just ...
1.2
true
1
2,155
2012-10-12 02:49:37.290
Python Script to Make Another Script
I have looked around for a while now and am still unable to find an answer to a method of doing this. I have made a few scripts to solve equations and now am looking for a way to write a script that will allow input of steps into an equation,number and name of variables etc. My idea is to make a script that will take a...
Instead of writing a script that creates another script, a better way to solve the problem would be to write functions. For example, the first function would read the names of variables, etc. and return these data as a dictionary. Next, you would pass this dictionary into the second function, which, depending on the ...
1.2
true
1
2,156
2012-10-12 15:27:25.397
Have python process talk back on SIGUSR1 call
I have a python script that can run for long time in the background, and am trying to find a way of getting a status update from it. Basically we're considering to send it a SIGUSR1 signal, and then have it report back a status update. Catching the signal in Python is not the issue, lots of information about that. But ...
Signals are not designed to be general inter-process communication mechanisms that allow for passing data. They can't do much more than provide a notification. What the target process does in response can be fairly general (generating output to a particular file that the sender then knows to go look at, for example), b...
1.2
true
1
2,157
2012-10-12 21:38:28.870
Recursive Function To Help Clear Tiles (Field Of View)
I am attempting to teach myself python and have hit a rough spot once it has come to recursion. I have done the classic recursive functions (factorial, fibonacci numbers...) but I am going back over old code and trying to convert most of my iterative functions to recursive functions for practice. This is the wall that ...
I find it helps a LOT to express recursions in words. What the algorithm says is basically "what's visible at radius N is what's visible from radius N-1". Like, uh, the edge gets bigger.
0.201295
false
1
2,158
2012-10-13 13:26:04.030
How to run a Python project?
I have installed the Enthought Python distribution on my computer, but I don't have any idea how to use it. I have PyLab and IDLE but I want to run .py files by typing the following command: python fileName.py I don't know where to write this command: IDLE, PyLab or Python.exe or Windows command prompt. When I do thi...
Open a command prompt: Press ⊞ Win and R at the same time, then type in cmd and press ↵ Enter Navigate to the folder where you have the ".py" file (use cd .. to go one folder back or cd folderName to enter folderName) Then type in python filename.py
1.2
true
2
2,159
2012-10-13 13:26:04.030
How to run a Python project?
I have installed the Enthought Python distribution on my computer, but I don't have any idea how to use it. I have PyLab and IDLE but I want to run .py files by typing the following command: python fileName.py I don't know where to write this command: IDLE, PyLab or Python.exe or Windows command prompt. When I do thi...
Indeed, the command to run a Python file should be run in the command prompt. Python should be in your path variable for it to work flexible. When the python folder is added to path you can call python everywhere in the command prompt, otherwise just in your python install folder. The following is from the python websi...
0.386912
false
2
2,159
2012-10-15 06:06:37.333
Using Java RMI to invoke Python method
I have a remote method created via Python web2py. How do I test and invoke the method from Java? I was able to test if the method implements @service.xmlrpc but how do i test if the method implements @service.run?
I'd be astonished if you could do it at all. Java RMI requires Java peers.
0.101688
false
1
2,160
2012-10-15 09:57:58.890
How to Submit Https authentication with Selenium in python
I want to access with Selenium (through) Python, a URL that demands authentication. When visit the URL, manually a new authentication window pops up, on which I need to fill in a username and password. Only after clicking on “OK” this window disappears and I return to the original site. As I want to visit this URL on a...
Using driver.get("https://username:password@somewebsite.com/") should directly log you in, without the popup being displayed, What about this did not work for you? EDIT I am not sure this will work but after driver.get("https://username:password@somewebsite.com/") Try accepting alert. For the alert - @driver.switch_t...
0.386912
false
1
2,161
2012-10-16 07:14:11.203
How to Transfer Files from Client to Server Computer by using python script?
I am writing a python script to copy python(say ABC.py) files from one directory to another directory with the same folder name(say ABC) as script name excluding .py. In the local system it works fine and copying the files from one directory to others by creating the same name folder. But actually I want copy these fi...
I used the same script, but my host failed to respond. My host is in different network. WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
-0.201295
false
1
2,162
2012-10-17 14:23:55.413
tcp/ip port exhaustion with selenium webdriver
I'm working on a suite of tests using selenium webdriver (written in Python). The page being tested contains a form that changes its displayed fields based upon what value is selected in one of its select boxes. This select box has about 250 options. I have a test (running via nose, though that's probably irrelevant...
In as much as a small amount of plastic explosive solves the problem of forgetting your house keys, I implemented a solution. I created a class that tracks a list of resources and the time they were added to it, blocks when a limit is reached, and removes entries when their timestamp passes beyond a timeout value. I ...
0.265586
false
1
2,163
2012-10-18 07:48:43.463
Regex routing in Python using Tornado framework
i currently have this in my routing: (r"/admin", AdminController.Index ), (r"/admin/", AdminController.Index ), how do i merge them with just one line and have admin and admin/ go to AdminController.Index? i know this could be achieved via regex, but it doesnt seem to work
What about this: r'/admin/?' or r'/admin/{0,1}? Pay attention that I'm only talking about regex, don't know if this would work in Django.
1.2
true
1
2,164
2012-10-18 11:26:22.183
Why does SimpleHTTPServer redirect to ?querystring/ when I request ?querystring?
I like to use Python's SimpleHTTPServer for local development of all kinds of web applications which require loading resources via Ajax calls etc. When I use query strings in my URLs, the server always redirects to the same URL with a slash appended. For example /folder/?id=1 redirects to /folder/?id=1/ using a HTTP 30...
The right way to do this, to ensure that the query parameters remain as they should, is to make sure you do a request to the filename directly instead of letting SimpleHTTPServer redirect to your index.html For example http://localhost:8000/?param1=1 does a redirect (301) and changes the url to http://localhost:8000/?p...
0.591696
false
1
2,165
2012-10-19 15:22:10.490
How can I bring up a python shell with packages already imported with a python script?
I want to bring up a python window (could be idle or cmd based) with some packages already imported by double clicking a python script. Is this possible? If so, how do I do it?
You can use the -i interpreter option. python -c "import os" -i will import the os module and go to the interpreter read/eval loop. You can also put some statements (imports, definitions, etc) on a file and load it with python -i <file.py>
0.591696
false
1
2,166
2012-10-22 18:24:55.810
Is sleep() blocking the handling of requests in Django?
In Django, if the view uses a sleep() function while answering a request, does this block the handling of the whole queue of requests? If so, how to delay an http answer without this blocking behavior? Can we do that out-of-the-box and avoid using a job queue like Celeri?
I would image that calling sleep() should block the execution of all Django code in most cases. However it might depend on the deployment architecture (e.g. gevent, gunicorn, etc). For instance if you are using a server which fires Django threads for each request, then no it will not block all the code. In most cases h...
0.673066
false
1
2,167
2012-10-24 12:45:34.893
Webapp2 + WTForms issue: How to pass values and errors back to user?
I am having a problem with webapp2 and wtforms. More specifically I have defined two methods in two different handlers, called: create, which is a GET method listening to a specific route save, which is a POST method listening to another route In the save method I validate my form and if fails, I want to redirect to ...
I think this will work if the routes are part of the same app. But why not using a single handler with get and put and a method _create, which can be called (self._create instead of a redirect) by get and put to render the template with the form. It is faster than a browser redirect and you can pass arguments in an eas...
1.2
true
1
2,168
2012-10-25 00:26:38.460
Wrapping a pygame surface around a viewport
I'm coding a game where the viewport follows the player's ship in a finite game world, and I am trying to make it so that the background "wraps" around in all directions (you could think of it as a 2D surface wrapped around a sphere - no matter what direction you travel in, you will end up back where you started). I ha...
I don't think so, I have an idea though. I'm guessing your background wraps horizontally and always to the right, then you could attach part of the beginning to the end of the background. Example, if you have a 10,000px background and your viewport is 1000px, attach the first 1000px to the end of the background, so you...
0
false
3
2,169
2012-10-25 00:26:38.460
Wrapping a pygame surface around a viewport
I'm coding a game where the viewport follows the player's ship in a finite game world, and I am trying to make it so that the background "wraps" around in all directions (you could think of it as a 2D surface wrapped around a sphere - no matter what direction you travel in, you will end up back where you started). I ha...
I was monkeying around with something similar to what you described that may be of use. I decided to try using a single map class which contained all of my Tiles, and I wanted only part of it loaded into memory at once so I broke it up into Sectors (32x32 tiles). I limited it to only having 3x3 Sectors loaded at once. ...
0
false
3
2,169
2012-10-25 00:26:38.460
Wrapping a pygame surface around a viewport
I'm coding a game where the viewport follows the player's ship in a finite game world, and I am trying to make it so that the background "wraps" around in all directions (you could think of it as a 2D surface wrapped around a sphere - no matter what direction you travel in, you will end up back where you started). I ha...
Thanks everyone for the suggestions. I ended up doing something a little different from the answers provided. Essentially, I made subsurfaces of the main surface and used them as buffers, displaying them as appropriate whenever the viewport included coordinates outside the world. Because the scrolling is omnidirectiona...
1.2
true
3
2,169
2012-10-25 01:00:47.713
how to write installer (installing python, python modules and other dependencies) for windows boxes?
I know nothing on this subject, but I need suggestions about the best tools or method for creating a setup program that installs python, some custom python modules, some other python modules such as PIL, and some EXE dependencies, all living on a network repository, on windows machines. In the repository are installers...
You can do this with any of the installer applications out there. Each of the dependent installers has a silent install option, so your installer just needs to invoke the installers for each of the dependencies in the right order. I won't recommend any windows installer application in particular because I don't like an...
0.545705
false
1
2,170
2012-10-25 01:40:59.683
sorting and selecting data
I have huge tables of data that I need to manipulate (sort, calculate new quantities, select specific rows according to some conditions and so on...). So far I have been using a spreadsheet software to do the job but this is really time consuming and I am trying to find a more efficient way to do the job. I use pytho...
This is a very general question, but there are multiple things that you can do to possibly make your life easier. 1.CSV These are very useful if you are storing data that is ordered in columns, and if you are looking for easy to read text files. 2.Sqlite3 Sqlite3 is a database system that does not require a server ...
0.201295
false
1
2,171
2012-10-26 16:06:24.097
zipped packages and in memory storage strategies
i have a multitenant app with a zipped package for each tenant/client which contains the templates and handlers for the public site for each of them. right now i have under 50 tenants and its fine to keep the imported apps in memory after the first request to that specific clients domain. this approach works well but i...
i agree with nick. there should be no python code in the tenant specific zip. to solve the memory issue i would cache most of the pages in the datastore. to serve them you don't need to have all tenants loaded in your instances. you might also wanna look in pre generating html views on save rather then on request.
0.386912
false
1
2,172
2012-10-29 18:16:39.667
Changing the shape of a pymunk/Chipmunk physics body
I am just getting started with pymunk, and I have a problem that I wasn't able to find a solution to in the documentation. I have a character body that changes shape during a specific animation. I know how to attach shapes to a physics body, but how do I change them? Specifically, I need to change the box to a smalle...
There are a couple of unsafe methods to modify a shape. Right now (v3.0) pymunk only supports updates of the Circle shape and the Segment shapes. However, I just committed a method to update the Poly shape as well, available in latest trunk of pymunk. If you dont want to run latest trunk I suggest you instead just rep...
1.2
true
1
2,173
2012-10-30 00:41:36.670
Python - get file path programmatically?
I am trying to create a Python program that uses the os.system() function to create a new process (application) based on user input... However, this only works when the user inputs "notepad.exe". It does not work, for instance, when a user inputs "firefox.exe". I know this is a path issue because the error says that th...
I think you can add the location of the files in the PATH environment variable. Follow the steps: Go to My Computer->Right click->Properties->Advanced System Settings->Click Environmental Variables. Now click PATH and then click EDIT. In the variable value field, go to the end and append ';' (without quotes) and then a...
1.2
true
1
2,174
2012-10-30 07:19:28.600
Setting default encoding Openerp/Python
Do you guys know how to change the default encoding of an openerp file? I've tried adding # -*- coding: utf-8 -*- but it doesn't work (is there a setup that ignore this command? just a wild guess). When I try to execute sys.getdefaultencoding() still its in ASCII. Regards
The comment # -*- coding: utf-8 -*- tells the python parser the encoding of the source file. It affects how the bytecode compiler converts unicode literals in the source code. It has no effect on the runtime environment. You should explicitly define the encoding when converting strings to unicode. If you are getting U...
0.999329
false
1
2,175
2012-10-30 13:34:53.833
lxml, parsing in reverse
I am parsing a large file (>9GB) and am using iterparse of lxml in Python to parse the file while clearing as I go forward. I was wondering, is there a way to parse backwards while clearing? I could see I how would implement this independently of lxml, but it would be nice to use this package. Thank you in advance!
iterparse() is strictly forward-only, I'm afraid. If you want to read a tree in reverse, you'll have to read it forward, while writing it to some intermediate store (be it in memory or on disc) in some form that's easier for you to parse backwards, and then read that. I'm not aware of any stream parsers that allow XML...
1.2
true
1
2,176
2012-10-30 15:01:26.173
How to automatic classification of app user reviews?
I have received tens of thousands of user reviews on the app. I know the meaning of many of the comments are the same. I can not read all these comments. Therefore, I would like to use a python program to analyze all comments, Identify the most frequently the most important feedback information. I would like to ask, ho...
You can use the Google Prediction API to characterize your comments as important or unimportant. What you'd want to do is manually classify a subset of your comments. Then you upload the manually classified model to Google Cloud Storage and, using the Prediction API, train your model. This step is asynchronous and can ...
0
false
1
2,177
2012-10-30 22:29:59.727
Appengine SDK 1.7.3 not detecting updated files
I just updated to SDK 1.7.3 running on Linux. At the same time I switched to the SQLite datastore stub, suggested by the depreciation message. After this, edits to source files are not always detected, and I have to stop and restart the SDK after updating, probably one time in ten. Is anyone else seeing this? Any ideas...
A similiar issue happens with appcfg.py in SDK 1.73, where it skips uploading some files sometimes. It looks like this only happens if appcfg.py is run under python 2.7. The workaround is to simply run appcfg.py under python 2.5. Then the upload works reliably. The code uploaded can still be 2.7 specific - it is only ...
0.545705
false
1
2,178
2012-10-31 10:07:50.497
How to create PDF documentation with Sphinx in Windows
I am using Sphinx to create documentation for my Python project in Windows. I need to generate PDF documentation. I found many explanation how to do this in Linux, but no good explanation how to do this in Windows. As far as i understand I need to create Latex format with Sphinx, and than use Texworks to convert Latex ...
As you have figured out: use Sphinx to generate LaTeX source, and then run it through a LaTex compiler to produce your PDF. Instead of troubling yourself with installing LaTeX (which can be daunting) and getting an editor set up, I suggest that you use one of the on-line LaTeX services. You then only have to create a p...
-0.135221
false
1
2,179
2012-10-31 11:21:18.170
Copying value of cell (X,Y) to cell (A,B) in same sheet of an Excel file using Python
I am using the modules xlwd, xlwt and xlutil to do some Excel manipulations in Python. I am not able to figure out how to copy the value of cell (X,Y) to cell (A,B) in the same sheet of an Excel file in Python. Could someone let me know how to do that?
Work on 2 cells among tens of thousands...quite meager. Normally,one should present an iteration over rows x columns.
0
false
1
2,180
2012-10-31 14:28:22.530
Link to python modules in emacs
I'm looking into emacs as an alternative to Eclipse. One of my favorite features in Eclipse is being able to mouse over almost any python object and get a listing of its source, then clicking on it to go directly to its code in another file. I know this must be possible in emacs, I'm just wondering if it's already impl...
I also switched from Eclipse to Emacs and I must say that after adjusting to more text-focused ways of exploring code, I don't miss this feature at all. In Emacs, you can just open a shell prompt (M-x shell). Then run IPython from within the Emacs shell and you're all set. I typically split my screen in half horizontal...
0.265586
false
1
2,181
2012-10-31 15:41:47.287
How can i call robocopy within a python script to bulk copy multiple folders?
I am trying to move multiple large folders (> 10 Gb , > 100 sub folders, > 2000 files ) between network drives. I have tried using shutil.copytree command in python which works fine except that it fails to copy a small percentage (< 1 % of files ) for different reasons. I believe robocopy is the best option for me as ...
Like halfs13 said use subprocess but you might need to format it like so from subprocess import call call(["robocopy",'fromdir', 'todir',"/S"]) Or else it may read the source as everything
0.3154
false
1
2,182
2012-10-31 16:21:06.173
picking the most relevant words from a paragraph
Not sure how to phrase this question properly, but this is what I intend to achieve using the hypothetical scenario outlined below - A user's email to me has just the SUBJECT and BODY, the subject being the topic of email, and the body being a description of the topic in just one paragraph of max 1000 words. Now I wou...
I am not an expert but it seems like you really need to define a notion of "key term", "relevance", etc, and then put a ranking algorithm on top of that. This sounds like doing NLP, and as far as I know there is a python package called NLTK that might be useful in this field. Hope it helps!
0.101688
false
1
2,183
2012-11-01 07:52:00.423
Can C programs have Python GUI?
My friend has an application written in C that comes with a GUI made using GTK under Linux. Now we want to rewrite the GUI in python (wxpython or PyQT). I don't have experience with Python and don't know how to make Python communicate with C. I'd like to know if this is possible and if yes, how should I go about implem...
If you have an option between C or C#(Sharp) then go with C# and use visual studio, you can build the GUI by dragging and dropping components easy. If you want to do something in python look up wxPython. Java has a built in GUI builder known as swing. You'll need some tutorials, but unless this program doesn't need to ...
0
false
1
2,184
2012-11-01 11:24:19.307
Python project organization
Yesterday I started an important Python project and since then I've been searching for documentation on how to organize the code to have a "high-quality" project. There is a lot of articles and official documentation about how to organize packages and modules but, as I'm very new to this language, I think that is not m...
Yes, your project will be a package. A module is a collection of related code. Most non-trivial projects will be a collection of modules in a package (potentially with sub-packages).
1.2
true
1
2,185
2012-11-01 12:28:19.737
Getting Responsive Django View
I have a HTML page which has four buttons Start, Stop, Pause and Resume in it. The functionality of the buttons are: Start Button: Starts the backend Simulator. (The Simulator takes around 3 minutes for execution.) Stop Button: Stops the Simulator. Pause Button: Pauses the Simulator. Resume Button: Resumes the Simulat...
Easiest I think will be use ajax to start he simulator. Response for start request can be updated on the same page. However, you will still have to think about how to pause,resume and stop the simulator started by earlier requests. i.e how to manage and manipulate state of the simulator. May be you want to update that ...
0
false
1
2,186
2012-11-02 21:59:30.013
Big-O of list slicing
Say I have some Python list, my_list which contains N elements. Single elements may be indexed by using my_list[i_1], where i_1 is the index of the desired element. However, Python lists may also be indexed my_list[i_1:i_2] where a "slice" of the list from i_1 to i_2 is desired. What is the Big-O (worst-case) notation ...
For a list of size N, and a slice of size M, the iteration is actually only O(M), not O(N). Since M is often << N, this makes a big difference. In fact, if you think about your explanation, you can see why. You're only iterating from i_1 to i_2, not from 0 to i_1, then I_1 to i_2.
0.997458
false
1
2,187
2012-11-03 05:31:57.013
Cropping away transparent pixels but preserving the offset
I have a group of .png files where most of the image is transparent (alpha channel), but there is image in the middle (non-transparent pixels) that I need to extract. What I need to do is crop the image down to just the non-transparent pixels, but I need to know how many pixels were cropped off the left and bottom so w...
You mentioned that you were having problems installing PIL on a Mac. Have you considered using Macports?
0
false
1
2,188
2012-11-03 19:28:21.327
Extracting strings from a physical drive
I'm looking to write a script in Python 2.x that will scan physical drive (physical and not logical) for specific strings of text that will range in size (chat artifacts). I have my headers and footers for the strings and so I am just wondering how is best to scan through the drive? My concern is that if I split it int...
Your problem can be formulated as "how do I search in a very long file with no line structure." It's no different from what you'd do if you were reading line-oriented text one line at a time: Imagine you're reading a text file block by block, but have a line-oriented regexp to search with; you'd search up to the last c...
0.386912
false
1
2,189
2012-11-04 01:04:32.743
How to strip trailing digits from a string
I have a variable text whose value is like below,I need strip of trailing digits,is there a python built-in function to do it..if not,please suggest how can this be done in python e.g. -text=A8980BQDFZDD1701209.3 => -A8980BQDFZDD
You can use rstrip. Check the python docs.
1.2
true
1
2,190
2012-11-04 03:43:37.487
Separate strings from other iterables in python 3
I'm trying to determine whether a function argument is a string, or some other iterable. Specifically, this is used in building URL parameters, in an attempt to emulate PHP's &param[]=val syntax for arrays - so duck typing doesn't really help here, I can iterate through a string and produce things like &param[]=v&param...
You've been seeing things that somewhat conflict based on Python 2 vs 3. In Python 3, isinstance(foo, str) is almost certainly what you want. bytes is for raw binary data, which you probably can't include in an argument string like that. The python 2 str type stored raw binary data, usually a string in some specific en...
1.2
true
1
2,191
2012-11-04 20:33:34.873
Can you run python as a windowed program?
Hello fellow python users, I bring forth a question that I have been wondering for a while. I love python, and have made many programs with it. Now what I want to do is (or know how to do) make a python program, but run it in a window with buttons that you click on instead of typing in numbers to elect things. I woul...
You can do this, the library is called tkinter.
0
false
2
2,192
2012-11-04 20:33:34.873
Can you run python as a windowed program?
Hello fellow python users, I bring forth a question that I have been wondering for a while. I love python, and have made many programs with it. Now what I want to do is (or know how to do) make a python program, but run it in a window with buttons that you click on instead of typing in numbers to elect things. I woul...
There are many GUI libraries to choose from, but I like Tkinter because it's easy and there's nothing to install (it comes with Python). But some people prefer wxPython or others, such as PyQT. You'll have to decide which you like, or just go with Tkinter if you don't want to go through the trouble of installing librar...
0
false
2
2,192
2012-11-05 13:27:41.747
using neo4J (server) from python with transaction
I'm currently building a web service using python / flask and would like to build my data layer on top of neo4j, since my core data structure is inherently a graph. I'm a bit confused by the different technologies offered by neo4j for that case. Especially : i originally planned on using the REST Api through py2neo ,...
None of the REST API clients will be able to explicitly support (proper) transactions since that functionality is not available through the Neo4j REST API interface. There are a few alternatives such as Cypher queries and batched execution which all operate within a single atomic transaction on the server side; however...
1.2
true
1
2,193
2012-11-05 14:32:16.047
"error: cannot locate an Oracle software installation" When trying to install cx_Oracle
Newbie here trying to use python to do some database analysis. I keep getting the error: "error: cannot locate an Oracle software installation" When installing CX_oracle (via easy_install). The problem is I do not have oracle on my local machine, I'm trying to use python to connect to the main oracle server. I have h...
Tip for Ubuntu users After configuring .bashrc environment variables, like it was explained in other answers, don't forget to reload your terminal window, typing $SHELL.
0.067922
false
3
2,194
2012-11-05 14:32:16.047
"error: cannot locate an Oracle software installation" When trying to install cx_Oracle
Newbie here trying to use python to do some database analysis. I keep getting the error: "error: cannot locate an Oracle software installation" When installing CX_oracle (via easy_install). The problem is I do not have oracle on my local machine, I'm trying to use python to connect to the main oracle server. I have h...
I got this message when I was trying to install the 32 bit version while having the 64bit Oracle client installed. What worked for me: reinstalled python with 64 bit (had 32 for some reason), installed cx_Oracle (64bit version) with the Windows installer and it worked perfectly.
0.135221
false
3
2,194
2012-11-05 14:32:16.047
"error: cannot locate an Oracle software installation" When trying to install cx_Oracle
Newbie here trying to use python to do some database analysis. I keep getting the error: "error: cannot locate an Oracle software installation" When installing CX_oracle (via easy_install). The problem is I do not have oracle on my local machine, I'm trying to use python to connect to the main oracle server. I have h...
I installed cx_Oracle, but I also had to install an Oracle client to use it (the cx_Oracle module is just a common and pythonic way to interface with the Oracle client in Python). So you have to set the variable ORACLE_HOME to your Oracle client folder (on Unix: via a shell, for instance; on Windows: create a new varia...
0.135221
false
3
2,194
2012-11-05 16:38:17.913
How to put files in folders using py2exe.
Hi!I made a chess engine in python which i then compiled to .exe using py2exe. The problem is that it doesn't look very neat when i have all the strange files gathered together in the same folder (dist). I'd like to make a new folder inside the dist folder that contains all the helper files, so all my dist folder conta...
There is a feature in the configuration of py2exe that allows you to bundle all the Python files in a single library.zip file. That would considerably reduce the amount of files in the root directory, but there will still remain some files, regardless of all that. These files are generally DLL files, at least from what...
1.2
true
1
2,195
2012-11-07 01:07:15.690
How to count tweets from query without double counting?
I'm working on a project which requires counting the number of tweets that meet the parameters of a query. I'm working in Python, using Twython as my interface to Twitter. A few questions though, how do you record which tweets have already been accounted for? Would you simply make a note of the last tweet ID and ignore...
considering the case of similar tweets and retweets, I would recommend making a semantic note of the whole tweet, extracting the text part of each tweet and doing a dictionary lookup. but tweet id is more simpler with significant loss, usage as noted above.
0
false
1
2,196
2012-11-08 20:26:01.867
Where to use ipython and where is ipthon shell?
I've installed ipython, but I don't know how to use it. Where could I find ipython shell?
To use ipython, just go to the command line, and run the command ipython.
0.496174
false
1
2,197
2012-11-09 16:12:55.833
Efficiency of calling C function from Python
I wrote a python script to do some experiment with the Mandelbrot set. I used a simple function to find Mandelbrot set points. I was wondering how much efficiency I can achieve by calling a simple C function to do this part of my code? Please consider that this function should call many times from Python. What is the e...
You'll want the python calls to your C function to be as little as possible. If you can call the C function once from python and get it to do most/all of the work, that would be better.
0.386912
false
1
2,198
2012-11-09 17:37:12.817
Appengine Search API - Globally Consistent
I've been using the appengine python experimental searchAPI. It works great. With release 1.7.3 I updated all of the deprecated methods. However, I am now getting this warning: DeprecationWarning: consistency is deprecated. GLOBALLY_CONSIST However, I'm not sure how to address it in my code. Can anyone point me in the ...
This depends on whether or not you have any globally consistent indexes. If you do, then you should migrate all of your data from those indexes to new, per-document-consistent (which is the default) indexes. To do this: Loop through the documents you have stored in the global index and reindexing them in the new index...
0
false
1
2,199
2012-11-10 01:19:20.710
Scrapyd: How to specify libs and common folders that deployed projects can use?
Scrapyd is service where we can eggify deploy our projects. However I am facing a problem. I have a Project named MyScrapers whose spider classes uses an import statement as follows: from mylibs.common.my_base_spider import MyBaseSpider The path to my_base_spider is /home/myprojectset/mylibs/common/my_base_spider While...
I found the answer by adding mylibs to site-packages of python by using setup.py inside mylib folder. That way I could import everything inside mylib in my projects. Actually mylibs were way outside from the location where setup.py of my deploy-able project is present. setup.py looks for packages on same level and insi...
1.2
true
1
2,200
2012-11-11 14:55:16.703
How to use `subprocess` command with pipes
I want to use subprocess.check_output() with ps -A | grep 'process_name'. I tried various solutions but so far nothing worked. Can someone guide me how to do it?
Also, try to use 'pgrep' command instead of 'ps -A | grep 'process_name'
0.179442
false
1
2,201
2012-11-12 15:38:46.513
Installing Python modules for OpenERP 6.1 in Windows
I installed OpenERP 6.1 on windows using the AllInOne package. I did NOT install Python separately. Apparently OpenERP folders already contain the required python executables. Now when I try to install certain addons, I usually come across requirements to install certain python modules. E.g. to install Jasper_Server, I...
Good question.. Openerp on windows uses a dll for python (python26.dll in /Server/server of the openerp folder in program files). It looks like all the extra libraries are in the same folder, so you should be able to download the extra libraries to that folder and restart the service. (I usually stop the service and ru...
0.201295
false
1
2,202
2012-11-12 22:42:05.177
Querying twitter streaming api keywords from a database
I'm filtering the twitter streaming API by tracking for several keywords. If for example I only want to query and return from my database tweet information that was filtered by tracking for the keyword = 'BBC' how could this be done? Do the tweet information collected have a key:value relating to that keyword by which...
Unfortunately, the Twitter API doesn't provide a way to do this. You can try searching through receive tweets for the keywords you specified, but it might not match exactly.
0
false
1
2,203
2012-11-13 18:12:27.580
How can the built-in range function take a single argument or three?
How can the range function take either: a single argument, range(stop), or range(start, stop), or range(start, stop, step). Does it use a variadic argument like *arg to gather the arguments, and then use a series of if statements to assign the correct values depending on the number of arguments supplied? In essence, d...
Range takes, 1, 2, or 3 arguments. This could be implemented with def range(*args), and explicit code to raise an exception when it gets 0 or more than 3 arguments. It couldn't be implemented with default arguments because you can't have a non-default after a default, e.g. def range(start=0, stop, step=1). This is esse...
1.2
true
1
2,204
2012-11-14 04:24:50.647
Importing a function from a .txt file
Is there any way to do this? Basically I have a file that I want a user to be able to edit via a GUI I built(all of which I can do easily). Part of this is a calculation in a function. That or being able to edit a .py file from another file would be fine as well, but it is hard to find anything on that because every se...
yup, its not at all secure, but eval is the way to go: In [1]: a= 10 In [2]: b= 20 In [3]: eval('a + 10*b') Out[3]: 210
1.2
true
1
2,205
2012-11-14 04:59:23.910
Complex number in ctypes
This might be a bit foolish but I'm trying to use ctypes to call a function that receives a complex vector as a paramter. But in ctypes there isn't a class c_complex. Does anybody know how to solve this? edit: I'm refering to python's ctypes, in case there are others....
If c_complex is a C struct and you have the definition of in documentation or a header file you could utilize ctypes to compose a compatible type. It is also possible, although less likely, that c_complex is a typdef for a type that ctypes already supports. More information would be needed to provide a better answer.....
-0.081452
false
1
2,206
2012-11-14 18:34:56.590
In python, how can I efficiently find a consecutive sequence that is a subset of a larger consecutive sequence?
I need to find all the days of the month where a certain activity occurs. The days when the activity occurs will be sequential. The sequence of days can range from one to the entire month, and the sequence will occur exactly one time per month. To test whether or not the activity occurs on any given day is not an expe...
I think the linear probe suggested by @isbadawi is the best way to find the beginning of the subsequence. This is because the subsequence could be very short and could be anywhere within the larger sequence. However, once the beginning of the subsequence is found, we can use a binary search to find the end of it. Tha...
1.2
true
1
2,207
2012-11-15 00:22:30.903
Convert an EXE and its dependencies into one stand-alone EXE
I'm using cx_Freeze to compile Python programs into executables and it works just fine, but the problem is that it doesn't compile the program into one EXE, it converts them into a .exe file AND a whole bunch of .dll files including python32.dll that are necessary for the program to run. Does anyone know how I can pack...
Have you tried innosetup? It can create installer files from the output of cxfreeze. There might be an option somewhere to bundle everything into one file.
0
false
1
2,208
2012-11-15 09:51:44.963
How to expose an NLTK based ML(machine learning) Python Script as a Web Service?
Let me explain what I'm trying to achieve. In the past while working on Java platform, I used to write Java codes(say, to push or pull data from MySQL database etc.) then create a war file which essentially bundles all the class files, supporting files etc and put it under a servlet container like Tomcat and this becom...
NLTK based system tends to be slow at response per request, but good throughput can be achieved given enough RAM.
0
false
1
2,209
2012-11-15 10:01:18.273
Python import in __init__()
I need to have an import in __init__() method (because i need to run that import only when i instance the class). But i cannot see that import outside __init__(), is the scope limited to__init__? how to do?
You can just import it again other places that you need it -- it will be cached after the first time so this is relatively inexpensive. Alternatively you could modify the current global namespaces with something like globals()['name'] = local_imported_module_name. EDIT: For the record, although using the globals() func...
0.470104
false
1
2,210
2012-11-17 03:45:04.757
Pass data in google app engine using POST
I'm trying to pass a variable from one page to another using google app engine, I know how to pass it using GET put putting it in the URL. But I would like to keep the URL clean, and I might need to pass a larger amount of data, so how can pass info using post. To illustrate, I have a page with a series of links, each...
Links inherently generate GET requests. If you want to generate a POST request, you'd need to either: Use a form with method="POST" and submit it, or Use AJAX to load the new page.
1.2
true
1
2,211
2012-11-17 06:31:23.443
Python Flushing and Already Closed File
How do I add a check to avoid flushing a file f with f.flush() when some function has already done f.close()? I can't seem to figure out how to do so :/
Just examine closed attribute of file object.
0.545705
false
1
2,212
2012-11-17 16:54:28.467
List of Dictionary words without apostrophes
I am looking for a dictionary file containing only words without apostrophes. I cant seem to find one! Does anyone know how where I can find one, if not how could I eliminate those words from the file using Python?
On Linux: A nice method using grep to filter out any words containing apostrophes in the words file and save to mywords.txt in your home directory. grep "^[^']*$" /usr/share/dict/words > ~/mywords.txt No need to install, download or write any code! On OS X: Even easier as /usr/share/dict/words contains no words with ...
0.135221
false
1
2,213
2012-11-17 20:52:06.693
Web scraping - web login issue
So I am trying to scrape something that is behind a login system. I tried using CasperJS, but am having issues with the form, so maybe that is not the way to go; I checked the source code of the site and the form name is "theform" but I can never login must be doing something wrong. Does any have any tutorials on how t...
Because you mentioned CasperJS I can assume that web site generate some data by using JavaScript. My suggestion would be check WebKit. It is a browser "engine", that will let you do what ever you want with web-site. You can use PyQt4 framework, which is very good, and has a good documentation.
0
false
1
2,214
2012-11-17 23:55:27.250
K-Means plus plus implementation
My score was to get the most frequent color in a image, so I implemented a k-means algorithm. The algorithm works good, but the result is not the one I was waiting for. So now I'm trying to do some improvements, the first I thought was to implement k-means++, so I get a beter position for the inicial clusters centers. ...
You can use a vector quantisation. You can make a list of each pixel and each adjacent pixel in x+1 and y+1 direction and pick the difference and plot it along a diagonale. Then you can calculate a voronoi diagram and get the mean color and compute a feature vector. It's a bit more effectice then to use a simple grid ...
1.2
true
1
2,215
2012-11-18 12:28:58.903
Python/Django: how to get files fastest (based on path and name)
My website users can upload image files, which then need to be found whenever they are to be displayed on a page (using src = ""). Currently, I put all images into one directory. What if there are many files - is it slow to find the right file? Are they indexed? Should I create subdirectories instead? I use Python/Dja...
The access time for an individual file are not affected by the quantity of files in the same directory. running ls -l on a directory with more files in it will take longer of course. Same as viewing that directory in the file browser. Of course it might be easier to work with these images if you store them in a subdir...
1.2
true
1
2,216
2012-11-19 05:49:18.757
In practice, how eventual is the "eventual consistency" in HRD?
I am in the process of migrating an application from Master/Slave to HRD. I would like to hear some comments from who already went through the migration. I tried a simple example to just post a new entity without ancestor and redirecting to a page to list all entities from that model. I tried it several times and it w...
If you have a small app then your data probably live on the same part of the same disk and you have one instance. You probably won't notice eventual consistency. As your app grows, you notice it more. Usually it takes milliseconds to reach consistency, but I've seen cases where it takes an hour or more. Generally, quer...
1.2
true
3
2,217
2012-11-19 05:49:18.757
In practice, how eventual is the "eventual consistency" in HRD?
I am in the process of migrating an application from Master/Slave to HRD. I would like to hear some comments from who already went through the migration. I tried a simple example to just post a new entity without ancestor and redirecting to a page to list all entities from that model. I tried it several times and it w...
The replication speed is going to be primarily server-workload-dependent. Typically on an unloaded system the replication delay is going to be milliseconds. But the idea of "eventually consistent" is that you need to write your app so that you don't rely on that; any replication delay needs to be allowable within the ...
0
false
3
2,217
2012-11-19 05:49:18.757
In practice, how eventual is the "eventual consistency" in HRD?
I am in the process of migrating an application from Master/Slave to HRD. I would like to hear some comments from who already went through the migration. I tried a simple example to just post a new entity without ancestor and redirecting to a page to list all entities from that model. I tried it several times and it w...
What's the worst case if you get inconsistent results? Does a user see some unimportant info that's out of date? That's probably ok. Will you miscalculate something important, like the price of something? Or the number of items in stock in a store? In that case, you would want to avoid that chance occurence. From ...
0
false
3
2,217
2012-11-19 09:28:04.363
Pygame: Graphical Input + Text Input
In Pygame, how can I get graphical input(e.g. clicking exit button) and also get input from the a terminal window simultaneously? To give you context, my game has a GUI but gets its game commands from a "input()" command. How can I look for input from the command line while also handling graphics? I'm not sure if this...
You can't do that, unless you use the input command in a different thread, but then you have to deal with syncronization (which might be what you want or don't want to do). The way I'd implement this is to create a kind of in-game console. When a special key (e.g. '\') is pressed you make the console appear, and when y...
1.2
true
1
2,218
2012-11-19 18:57:15.177
How to specify browser binary in selenium remote webdriver?
I'm trying to use Firefox portable for my tests in python. In plain webdriver it works, but i was wondering how to do it in remote webdriver. All i could find is how to pass firefox profile, but how to specify to webdriver which binary to use?
Very hacky, but you could modify the Webdriver Firefox plugin to point to your binary.
0
false
1
2,219
2012-11-19 23:46:19.673
python library access in ubuntu 12.04
I am learning python from learnpythonthehardway. in the windows I had no issues with going through a lots of exercises because the setup was easier but I want to learn linux as well and ubuntu seemed to me the nicest choice. now I am having trouble with setting up. I can get access to the terminal and then usr/lib/pyt...
As an absolute beginner, don't worry right now about where to install libraries. Simple example scripts that you're trying out for learning purposes don't belong being installed in any lib directory such as under /usr/lib/python.' On Linux you want to do most work in your home directory, so just cd ~ to make sure you'...
1.2
true
1
2,220
2012-11-20 12:44:21.610
How do I make a web server to make timed multiple choice tests?
I'd like to make a webapp that asks people multiple choice questions, and times how long they take to answer. I'd like those who want to, to be able to make accounts, and to store the data for how well they've done and how their performance is increasing. I've never written any sort of web app before, although I'm a g...
When the server-side creates the form, encode an hidden field with the timestamp of the request, so when the users POSTs his form, you can see the time difference. How to implement that is up to you, which server you have available, and several other factors.
0.101688
false
1
2,221
2012-11-20 15:23:24.817
PIL: how to draw € on an image with draw.text?
I have a title ("cadeau check 50 €") in a form value that I want to write to a background image with arial.ttf. My text is correct but for the euro sign. I have 2 [] in place. I don't know where the problem is coming from. Is this an encoding problem in PIL, or have I a problem with the font?
Maybe use Unicode strings?? Like u'cadeau check 50 €' ... Now, does also your font have the corresponding glyphs?
0
false
1
2,222
2012-11-20 17:44:07.173
How do I import from a child directory / subfolder?
From main.py, I want to import a file from the backend folder WebAppName/main.py WebAppName/backend/handlers.py How do I specify this as an import statement I am aware that importing from the same folder is just import handlers But this is a child directory, so how do I do this?
You need to have an __init__.py file in the backend folder for Python to consider it a package. Then you can do import backend.handlers or from backend.handlers import foo
0.265586
false
1
2,223
2012-11-21 00:23:27.057
"No user interaction allowed" When running AppleScript in python
I have the applescript which will displays menu list and allow user to select menu items etc. It runs fine by itself. And now I try to run it in python. I get the No user interaction allowed. (-1713) error. I looked online. I tried the following: add on run function in the same applescript, so what i did is just a...
My issue was an app with LSBackgroundOnly = YES set attempting to run an AppleScript that displays UI, such as display dialog ... Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" AppleScript.scpt: execution error: No user interaction allowed. (-1713) Using tell application "Finder" ... or etc. works...
0
false
1
2,224
2012-11-21 05:51:28.630
how to write to shared memory in python from stream?
I have a processes from several servers that send data to my local port 2222 via udp every second. I want to read this data and write it to shared memory so there can be other processes to read the data from shared memory and do things to it. I've been reading about mmap and it seems I have to use a file... which I can...
First, note that what you're trying to build will require more than just shared memory: it's all well if a.py writes to shared memory, but how will b.py know when the memory is ready and can be read from? All in all, it is often simpler to solve this problem by connecting the multiple processes not via shared memory, ...
0
false
2
2,225
2012-11-21 05:51:28.630
how to write to shared memory in python from stream?
I have a processes from several servers that send data to my local port 2222 via udp every second. I want to read this data and write it to shared memory so there can be other processes to read the data from shared memory and do things to it. I've been reading about mmap and it seems I have to use a file... which I can...
mmap doesn't take a file name but rather a file descriptor. It performs the so-called memory mapping, i.e. it associates pages in the virtual memory space of the process with portions of the file-like object, represented by the file descriptor. This is a very powerful operation since it allows you: to access the conte...
0
false
2
2,225
2012-11-21 23:10:06.700
"Force" User Input and Checking for correct Input Type
I have some functions calling for user input, sometimes string, int or whatever. so i noticed that if ENTER is pressed with NO INPUT i get an error. SO i did some research and i think i found that EVAL function may be what I'm looking for, but then again i read about its dangers. SO here are my questions: How can i ch...
To answer your second part of the question you can use the isinstance() function in python to check if a variable is of a certain type.
0
false
1
2,226
2012-11-22 18:02:23.720
Python3 can't find urllib3
I have Python 2.7.3 installed alongside Python 3.2.3 on an Ubuntu system. I've installed urllib3 using pip and can import it from the python shell. When I open the python3 shell, I get a can't find module error when trying to import urllib3. help('modules') from within the shell also doesn't list urllib3. Any ideas on ...
You need to install it for each version of Python you have - if pip installs it for Python 2.7, it won't be accessible from 3.2. There doesn't seem to be a pip-3.2 script, but you can try easy_install3 urllib3.
1.2
true
1
2,227
2012-11-23 04:10:52.760
Playing Video Files in Python
I'm making a game using Python with PyGame module. I am trying to make an introduction screen for my game using a video that I made since it was easier to make a video than coding the animation for the intro screen. The Pygame movie module does not work as stated on their site so I cannot use that. I tried using Pymedi...
I found a solution. The latest version of Pygame is still able to play MPEG-1 files. The problem was that there are different encoding of MPEG-1. The ones I found that works so far is Any Video Converter and Zamzar.com online converter. The downside to Zamzar is that it outputs really small version of the original vide...
1.2
true
1
2,228
2012-11-23 05:55:30.630
Transfer a Big File Python
Can someone give me a brief idea on how to transfer large files over the internet? I tried with sockets, but it does not work. I am not sure what the size of receiving sockets should be. I tried with 1024 bytes. I send the data from one end and keep receiving it at the other end. Is there any other way apart from socke...
I encountered the same problem, and i solved it by chopping the file up and then sending the parts separately (load the file, send file[0:512], then send file[512:1024] and so on. Before sending the file i sent the length of the file to the receiver so the it would know when its done. I know this probably isn't the bes...
1.2
true
1
2,229
2012-11-24 15:38:39.077
How to silence the commit function from the python apt library?
I use python apt library and I would like that the commit() function doesn't produce any output. I've searched on the web and saw that the fork function can do the trick but I don't know how to do that or if there exists another way. I don't use any GUI, I work via the terminal.
The use to fork is just a possibility I think. I've already try to redirect the sys.stdout even the sys.stderr : No Joy, it won't work.
0
false
1
2,230
2012-11-25 16:51:51.543
Boost.Python - communication with running C++ program
I read few Boost.Python tutorials and I know how to call C++ function from Python. But what I want to do is create C++ application which will be running in the background all the time and Python script that will be able to call C++ function from that instance of C++ application. The C++ application will be a game serve...
Boost python is useful for exposing C++ objects to python. Since you're talking about interacting with an already running application from python, and the lifetime of the script is shorter than the lifetime of the game server, I don't think boost python is what you're looking for, but rather some form of interprocess ...
0.673066
false
1
2,231
2012-11-25 20:40:09.153
Application that can load both C/C++ and Python plugins
I want to create an application that is capable of loading plugins. The twist is that I want to be able to create plugins in both C/C++ and Python. So I've started thinking about this and have a few questions that I'm hoping people can help me with. My first question is whether I need to use C/C++ for the "core" of the...
Write your application in Python, then you can have a folder for your plugins. Your application searches for them by checking the directory/traversing the plugin tree. Then import them via "import" or use ctypes for a .so/.dll, or even easier: you can use boost::python for creating a .so/.dll that you can 'import' lik...
0.386912
false
1
2,232
2012-11-26 21:20:55.197
Python module issue
I have a shared hosting environment on Bluehost. I am running a custom installation of python(+ django) with a few installed modules. All has been working, until yesterday a change was made on the server(I assume) which gave me this django error: ... File "/****/****/.local/lib/python/django/utils/importlib.py", line ...
You were right. Bluehost upgraded MySQL. Here is what I did: 1) remove the "build" directory in the "MySQL-python-1.2.3" directory 2) remove the egg 3) build the module again "python setup.py build" 4) install the module again "python setup.py install --prefix=$HOME/.local" Morale of the story for me is to remove the o...
0
false
2
2,233
2012-11-26 21:20:55.197
Python module issue
I have a shared hosting environment on Bluehost. I am running a custom installation of python(+ django) with a few installed modules. All has been working, until yesterday a change was made on the server(I assume) which gave me this django error: ... File "/****/****/.local/lib/python/django/utils/importlib.py", line ...
I think you upgraded your OS installation which in turn upgraded libmysqlclient and broke native extension. What you can do is reinstall libmysqlclient16 again (how to do it depends your particular OS) and that should fix your issue. Other approach would be to uninstall MySQLdb module and reinstall it again, forcing py...
1.2
true
2
2,233
2012-11-27 13:25:05.293
Subprocess in Reading Serial Port Read
Hi I am using Serial port communication to one of my device using python codes. It is sending a set of Hex code, Receives a set of data. process it. This data has to be stored in to a database. I have another script that has MYSQLdb library pushing it in to the database. If I do that in sequentially in one script i los...
use a pipe. Ceate two processes using the subprocess module, the first reads from the serial port and writes the set of hex codes to stdout. This is piped to the second process which reads from stdin and updates the database.
0.201295
false
1
2,234