Q_Id
int64
2.93k
49.7M
CreationDate
stringlengths
23
23
Users Score
int64
-10
437
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
DISCREPANCY
int64
0
1
Tags
stringlengths
6
90
ERRORS
int64
0
1
A_Id
int64
2.98k
72.5M
API_CHANGE
int64
0
1
AnswerCount
int64
1
42
REVIEW
int64
0
1
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
15
5.1k
Available Count
int64
1
17
Q_Score
int64
0
3.67k
Data Science and Machine Learning
int64
0
1
DOCUMENTATION
int64
0
1
Question
stringlengths
25
6.53k
Title
stringlengths
11
148
CONCEPTUAL
int64
0
1
Score
float64
-1
1.2
API_USAGE
int64
1
1
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
15
3.72M
20,010,125
2013-11-15T20:36:00.000
1
0
0
0
0
python,django
1
36,814,048
0
2
0
false
1
0
If you're using Firefox (or any browser) with Web Developer Toolbar, make sure you have cookies enabled. I temporarily had cookies turned off and forgot to turn it back on. Cookies => Disable Cookies => Disable All Cookies Solved my problem in Django 1.9.
1
2
0
0
I have multiple users in django auth setup and a few simple models. For superusers I can view my model objects. For non superusers that have is_staff checked I get a 403 Permission denied when trying to view my models. I have tried adding all permissions to those users to find out if that was the cause but still receive the forbidden message. Other than making them superusers I can't assign any more permissions. On the command line where I'm running the development server I see messages like "GET /admin/bcp/buildingsensor/24/ HTTP/1.1" 403 190614 Does anyone know how to get a more useful traceback for this so I know where to start looking. ? Thanks
Finding the cause of of 403 forbidden error in django admin
0
0.099668
1
0
0
6,383
20,026,876
2013-11-17T03:33:00.000
0
0
0
0
0
python,qt,pyqt4,fadein
0
20,217,728
0
1
0
false
0
1
I did same thing with QLabels, QButtons and other Widgets. There are different solutions accordingly on what you need. In my case I just created a custom component with a QTimer and a QGraphicsOpacityEffect. The timer increases or decreases the opacity value (by a coefficient)..
1
0
0
0
I want to place group of buttons ontop of a QLabel showing image, the question is how do I animate the fade in visibility of the QButtonGroup, I want to place my buttons at the bottom area so whenever pointer is at the bottom area the button group should animate to fully visible but if I move the pointer out of the bottom area, the button group should animate to a gradual fade out.
animate visibility of QButtonGroup or layout containing it
0
0
1
0
0
107
20,039,657
2013-11-18T03:36:00.000
0
0
0
0
0
python,django,sockets,web,remote-server
0
20,039,992
0
1
0
true
1
0
You basically have one major thing to decide: Is your embedded machine going to open up a port that allows any thing that knows it's IP and port details to control it and your web page write to that IP/Port OR Is your embedded device going to poll the web app to find out which state it should be in. The first option will normally respond faster but your embedded machine will be more vulnerable to outside interference, you will need to be able to run active code on your web server, which a lot of servers do not allow, etc. The second will only respond to state changes at an average of half the polling rate but will probably be simpler to program and manage. Plus your server is not also acting as a client.
1
0
0
0
I am now using Django frame work to build a website which has the ability to control a remote embedded system (simply with functions like "Turn ON/OFF"). What i can image now is to use Socket Programming with Python (because Django is pure Python). As i have learnt, i only know how to send and receive messages with sockets between the client machine and server. Can any one tell me 1. What else is needed to learn for this remote control function? 2. Or is there any better ways (better frameworks) to implement this? 3. Dose Django have built in methods for Socket Programming? (If not, is it possible to implement it with self-defined app)?
Remote control of an embedded system from Website
1
1.2
1
0
1
469
20,048,986
2013-11-18T13:27:00.000
2
0
1
0
0
python,rounding
0
20,049,872
0
2
0
false
0
0
It helps to know that anything to the power of 0 equals 1. As ndigits increases, the function: f(ndigits) = 10-ndigits gets smaller as you increase ndigits. Specifically as you increase ndigits by 1, you simply shift the decimal place of precision one left. e.g. 10^-0 = 1, 10^-1 = .1 and 10^-2 = .01. The place where the 1 is in the answer is the last point of precision for round. For the part where it says For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). This has unexpected behavior in Python 3 and it will not work for all floats. Consider the example you gave, round(123.455, 2) yields the value 123.45. This is not expected behavior because the closest even multiple of 10^-2 is 123.46, not 123.45! To understand this, you have to pay special attention to the note below this: Note The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float. And that is why certain floats will round to the "wrong value" and there is really no easy workaround as far as I am aware. (sadface) You could use fractions (i.e. two variables representing the numerator and the denominator) to represent floats in a custom round function if you want to get different behavior than the unpredictable behavior for floats.
1
3
0
0
Sorry, but I really don't know what's the meaning of the defination of round in python 3.3.2 doc: round(number[, ndigits]) Return the floating point value number rounded to ndigits digits after the decimal point. If ndigits is omitted, it defaults to zero. Delegates to number.__round__(ndigits). For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). The return value is an integer if called with one argument, otherwise of the same type as number. I don't know how come the multiple of 10 and pow. After reading the following examples, I think round(number,n) works like: if let number be 123.456, let n be 2 round will get two number:123.45 and 123.46 round compares abs(number-123.45) (0.006) and abs(number-123.46) (0.004),and chooses the smaller one. so, 123.46 is the result. and if let number be 123.455, let n be 2: round will get two number:123.45 and 123.46 round compares abs(number-123.45) (0.005) and abs(number-123.46) (0.005). They are equal. So round checks the last digit of 123.45 and 123.46. The even one is the result. so, the result is 123.46 Am I right? If not, could you offer a understandable version of values are rounded to the closest multiple of 10 to the power minus ndigits?
python 3.3.2 do I get the right understanding of the function "round"?
0
0.197375
1
0
0
675
20,072,309
2013-11-19T13:03:00.000
1
0
0
0
0
python,sql,flask,flask-sqlalchemy
0
20,081,554
0
2
1
false
1
0
The easiest way is to do the random number generation in javascript at the client end... Tell the client what the highest number row is, then the client page keeps track of which ids it has requested (just a simple js array). Then when the "request next random page" button is clicked, it generates a new random number less than the highest valid row id, and providing that the number isn't in its list of previously viewed items, it will send a request for that item. This way, you (on the server) only have to have 2 database accessing views: main page (which gives the js, and the highest valid row id) display an item (by id) You don't have any complex session tracking, and the user's browser is only having to keep track of a simple list of numbers, which even if they personally view several thousand different items is still only going to be a meg or two of memory. For performance reasons, you can even pre-fetch the next item as soon as the current item loads, so that it displays instantly and loads the next one in the background while they're looking at it. (jQuery .load() is your friend :-) ) If you expect a large number of items to be removed from the database (so that the highest number is not helpful), then you can instead generate a list of random ids, send that, and then request them one at a time. Pre-generate the random list, as it were. Hope this helps! :-)
1
1
0
0
I'm working on a web app in Python (Flask) that, essentially, shows the user information from a PostgreSQL database (via Flask-SQLAlchemy) in a random order, with each set of information being shown on one page. Hitting a Next button will direct the user to the next set of data by replacing all data on the page with new data, and so on. My conundrum comes with making the presentation truly random - not showing the user the same information twice by remembering what they've seen and not showing them those already seen sets of data again. The site has no user system, and the "already seen" sets of data should be forgotten when they close the tab/window or navigate away. I should also add that I'm a total newbie to SQL in general. What is the best way to do this?
Best way to show a user random data from an SQL database?
0
0.099668
1
1
0
512
20,082,935
2013-11-19T21:57:00.000
12
0
1
1
0
python,macos,python-3.x,pip,python-3.3
0
45,603,115
0
16
0
false
0
0
brew install python3 create alias in your shell profile eg. alias pip3="python3 -m pip" in my .zshrc ➜ ~ pip3 --version pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
3
140
0
0
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is: Download pyserial from pypi untar pyserial.tgz cd pyserial python3 setup.py install But I'd like to do like the cool kids do, and just do something like pip3 install pyserial. But it's not clear how I get to that point. And just that point. Not interested (unless I have to be) in virtualenv yet.
How to install pip for Python 3 on Mac OS X?
0
1
1
0
0
296,833
20,082,935
2013-11-19T21:57:00.000
4
0
1
1
0
python,macos,python-3.x,pip,python-3.3
0
52,130,224
0
16
0
false
0
0
pip is installed automatically with python2 using brew: brew install python3 pip3 --version
3
140
0
0
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is: Download pyserial from pypi untar pyserial.tgz cd pyserial python3 setup.py install But I'd like to do like the cool kids do, and just do something like pip3 install pyserial. But it's not clear how I get to that point. And just that point. Not interested (unless I have to be) in virtualenv yet.
How to install pip for Python 3 on Mac OS X?
0
0.049958
1
0
0
296,833
20,082,935
2013-11-19T21:57:00.000
0
0
1
1
0
python,macos,python-3.x,pip,python-3.3
0
55,175,708
0
16
0
false
0
0
For a fresh new Mac, you need to follow below steps:- Make sure you have installed Xcode sudo easy_install pip /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew doctor brew doctor brew install python3 And you are done, just type python3 on terminal and you will see python 3 installed.
3
140
0
0
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is: Download pyserial from pypi untar pyserial.tgz cd pyserial python3 setup.py install But I'd like to do like the cool kids do, and just do something like pip3 install pyserial. But it's not clear how I get to that point. And just that point. Not interested (unless I have to be) in virtualenv yet.
How to install pip for Python 3 on Mac OS X?
0
0
1
0
0
296,833
20,086,958
2013-11-20T03:47:00.000
0
0
0
0
0
python,canvas
0
20,093,393
0
1
0
false
0
1
You know the position of the two objects that can collide and compute the distance. When this is smaller than a threshold then they collide You use the Canvas.find_overlapping(*rectangle). to find out the figures on the canvas in a rectangle. I always prefer option 1. It helps dividing model and presentation to the user which do not always need to be linked.
1
0
0
0
So basically, I'm going to make a Brick Breaker type of game. Just my beginning CS Python class didn't teach much OO programming, and I was wondering how I could make this free moving ball register when it hits the slider. I think I have an idea, but I would like to see other peoples explanations.
How can I make one canvas object collside with another canvas object using Tkinter?
0
0
1
0
0
147
20,121,794
2013-11-21T13:03:00.000
0
0
1
0
0
python,image,path,cmd,pygame
0
20,121,823
0
2
0
false
0
0
Try looking at Relative Paths. Additionally, without seeing your image loading code it is really quite hard to help you.
1
0
0
0
I have following problem. When i am trying to open Python game files which i downloaded from internet (on the cmd), then i cant run them, because my computer doesn't find pictures which are in code. Even though the main code and pictures are in the same folder. If i insert full paths of the pictures locations, then everything is fine, but it takes too much time, with long code. So, my question is, how could i make my computer to open picture files, without me inserting full paths. Thanks if anyone could help.
The paths of picture locations in python
0
0
1
0
0
99
20,128,461
2013-11-21T17:57:00.000
0
0
1
0
0
python,pip
0
20,129,765
0
1
0
false
0
0
Ugly workaround: create virtualenv, install demanded package with pip, use pip list -o in both real environment and virtual one, compare output...
1
0
0
0
Is there a way to know if specific version is outdated? I know I can use pip list -o, but this goes over all packages, and I would like to get only for specific version. thanks. Eran
how to find if specifc version is outdated
1
0
1
0
0
44
20,139,979
2013-11-22T08:09:00.000
0
0
0
1
1
python,linux,django,windows,apache
0
20,140,905
0
1
0
false
1
0
I can think of some ways to do this: Use web services with real REST protocol and cross-site scripting protection Use WINE (As OneOfOnes suggested in his comment) But this is very risky for real production and might not work at all (or just when the load will become heavier) Write some code in the windows machine and call this code using something like Zero-MQ (ZMQ) or similar product Depending on the way your are using this library, One solution can fit better than the others. For most cases, I would suggest to go with ZMQ This way you can use much more complex models of communication (subscription-subscribers, send-response, and more) Also, using ZMQ would let you to scale in a very easy way if the need will come (you will be able to put few windows machines to process the requests) Edit: To support file transfer between machines, you have few options as well. Use ZMQ. File can be just a stream of data. No problem to support such a stream with ZMQ Use file server with some Enq. procedure Enq. can be done via ZMQ msg to inform the other side that the file is ready You can use folder share instead of a file server, but sharing files on the windows machine will not be a scale-able solution Windows program can send the file via FTP or SSH to the Linux server. Once again, signaling (file ready, file name,...) can be done with ZMQ
1
0
0
0
Background knowledge: Website in Django run under apache. Briefly speaking, I need to call an .exe program in a windows machine from a Linux machine. The reason for this is our website runs on Linux, but one module relies on Windows DLL. So we plan to put it on a separate windows server, and use some methods to call the exe program, and get the result back. My idea is: setup a web service on that windows machine, post some data to it, let itself deals with the exe program, and return some data as response. Notice that request data and response data will both contains files. I wonder if there is any neater way for this? EDIT: Thanks for @fhs, I found I didn't make my main problem clearly enough. Yes, the webservice could work. But the main disadvantages for this is: basically, I need to post several files to windows; windows receive files, save them, call the program using these files as parameters, and then package the result files into a zip and return it. In linux, receive the file, unpack it to local file system. It's kind of troublesome. So, is there any way to let both machines access the other one's files as easily as in local file system?
Calling exe in Windows from Linux
1
0
1
0
0
252
20,172,765
2013-11-24T08:55:00.000
0
0
0
0
0
python,network-programming,client-server
0
20,173,028
0
2
0
false
0
0
You may use Tornado. It is asynchronic multithreading web-server framework.
1
2
0
0
I am developing a server using python but the server can communicate with only one client at a time . Even if the server establish connection with more than one clients, it can't make conversation with all clients at the same time. One client should wait until the started conversation end, which may last for several minutes. This problem would create Tremendous delay up on the client which hasn't started conversation. So, how could I let my python server to communicate with more than one clients at the same time ? Thank you in advance
how can I make a server communicate with more than 1 client at the same time?
0
0
1
0
1
180
20,184,994
2013-11-25T04:53:00.000
5
0
0
0
0
ipython,ipython-notebook
0
30,234,937
0
3
0
false
0
0
%%HTML <style> div.prompt {display:none} </style> This will hide both In and Out prompts Note that this is only in your browser, the notebook itself isn't modified of course, and nbconvert will work just the same as before. In case you want this in the nbconverted code as well, just put the <style>div.prompt {display:none}</style> in a Raw NBConvert cell.
1
8
1
0
I am using nbconvert to produce something as close as possible to a polished journal article. I have successfully hidden input code using a custom nbconvert template. The doc is now looking very nice. But I don't know how to suppress the bright red 'out[x]' statement in the top left corner of the output cells. Anyone know of any settings or hacks that are able to remove this also ? Thanks, John
ipython notebook nbconvert - how to remove red 'out[N]' text in top left hand corner of cell output?
0
0.321513
1
0
0
5,150
20,198,589
2013-11-25T16:49:00.000
2
0
1
0
0
python,ptvs
0
20,203,996
0
1
0
true
0
0
When using the regular (non-debug) Python Interactive window, you can actually attach VS to the python.exe process that it is running by using Debug -> Attach to Process. Once that is done, if the interactive window does something to e.g. hit a breakpoint, the debugger will hit on that breakpoint. The tricky part is loading the code from a file in such a way that breakpoints are resolved. In particular, $load REPL command will not work because it just reads the file and evals it in the REPL line by line, without preserving the original file context. What you need is to load your script using Python facilities - e.g. import, or open+exec. There are also some gotchas there - e.g. the REPL window will become unresponsive whenever you are paused on a breakpoint.
1
1
0
0
When I'm developing in Python I often want to debug a specific method, in which case it makes sense to call the method from the interactive console or debug interactive console. However, when a method is called from the interactive windows in PTVS, it doesn't stop at the break points in said method. If it's possible, please tell me how to do it. If not, I would like to request this feature, and also to know if there is any quicker way to debug a specific method than calling it from the main script. I'm using PTVS 2.0 RC in Visual Studio 2013 Ultimate
Is it possible to debug a method called from the interactive window in PTVS?
1
1.2
1
0
0
1,144
20,200,295
2013-11-25T18:18:00.000
5
0
1
0
0
c++,python
0
20,200,392
0
5
0
false
0
0
looking at 110 (6 decimal) The Most Significant bit is 100 (4 decimal) // -- Note that this is always a power of 2 Create a mask: one less than the MSB is 011 (3 decimal) Mask off the highest bit using bitwise-and: 110 & 011 = 10 (2 decimal) Calculating the MSB (Most Significant Bit) has been handled here and elsewhere quite often
2
5
0
0
Is there an efficient way to remove the first bit of a number in C++ / Python, assuming you don't know how large the number is or its datatype? I know in Python I can do it by getting the bin(n), truncating the string by 1, and then recasting it to an int, but I am curious if there is a more "mathematical" way to do this. e.g. say the number is 6, which is 110 in binary. Chop the first bit and it becomes 10, or 2.
Removing first bit
0
0.197375
1
0
0
9,490
20,200,295
2013-11-25T18:18:00.000
2
0
1
0
0
c++,python
0
20,200,463
0
5
0
false
0
0
Well, you could create a loop in which you would double some variable (say x) in each iteration and then check whether this variable is greater than your number. If it is, divide it by two and subtract from your number. For example, if your number is 11: -first iteration: x=1<11, so continue -second iteration: x =2<11, so continue -third iteration: x=4<11, so continue -fourth iteration: x=8<11, so continue -fifth iteration: x=16>11, so divide x by two: x=8. Then subtract 8 from your number and get answer: 11-8=3.
2
5
0
0
Is there an efficient way to remove the first bit of a number in C++ / Python, assuming you don't know how large the number is or its datatype? I know in Python I can do it by getting the bin(n), truncating the string by 1, and then recasting it to an int, but I am curious if there is a more "mathematical" way to do this. e.g. say the number is 6, which is 110 in binary. Chop the first bit and it becomes 10, or 2.
Removing first bit
0
0.07983
1
0
0
9,490
20,209,874
2013-11-26T06:19:00.000
1
0
1
1
0
python,installation,gmp,mpfr,bigfloat
0
20,229,129
0
3
0
false
0
0
There are two versions of gmpy - version 1 (aka gmpy) and version 2 (aka gmpy2). gmpy2 includes MPFR. If you install gmpy2 then you probably don't need bigfloat since the functionality of MPFR can be directly accessed from gmpy2. Disclaimer: I maintain gmpy and gmpy2.
1
1
0
0
I am trying to install bigfloat in Python 3.2 on a Windows 7 machine. The documentation says that I first need to install GMP and MPFR. I have downloaded both of these to my desktop (as well as the bigfloat package). However as they are C packages I am not sure how to install them in python (I have tried to find a clear explanation for the last several hours and failed). Can any one either tell me what I need to do or point me to a tutorial? Thanks a lot, any help is greatly appreciated.
Installing bigfloat, GMP and MPFR in windows for python
0
0.066568
1
0
0
4,016
20,227,834
2013-11-26T20:59:00.000
0
0
0
0
1
python,algorithm,neo4j,recommendation-engine
0
20,237,347
0
1
1
true
1
0
I think you won't find any out-of-the box solution for you problem, as it is quite specific. What you could do with Neo4j is to store all your data that you use for building recommendations (users, friendships links, users' restaurants recommendations and reviews etc) and then build you recommendation engine on this data. From my experience it is quite straightforward to do once you get all your data in Neo4j (either with Cypher or Gremlin).
1
0
0
0
I have developed a search engine for restaurants. I have a social network wherein users can add friends and form groups and recommend restaurants to each other. Each restaurant may serve multiple cuisines. All of this in Python. So based on what restaurants a user has recommended, we can zero in on the kind of cuisines a user might like more. At the same time, we will know which price tier the user is more likely to explore(high-end, fast food, cafe, lounges etc) His friends will recommend some places which will carry more weightage. There are similar non-friend users who have the recommended some the restaurants the user has recommended and some more which the user hasn't. The end problem is to recommend restaurants to the user based on: 1) What he has recommended(Other restaurants with similar cuisines) - 50% weightage 2) What his friends have recommended(filtering restaurants which serve the cuisines the user likes the most) - 25% weightage 3) Public recommendation by 'similar' non-friend users - 25% weightage. I am spending a lot of time reading up on Neo4j, and I think Neo4j looks promising. Apart from that I tried pysuggest, but it didn't suit the above problem. I also tried reco4j but it is a Java based solution, whereas I'm looking for a Python based solution. There is also no activity on the Reco4j community, and it is still under development. Although I've researched quite a lot, I might be missing out on something. I'd like to know how would you go about implementing the above solution? Could you give any use cases for the same?
Recommendation engine using collaborative filtering in Python
0
1.2
1
0
0
1,190
20,233,650
2013-11-27T04:01:00.000
0
0
1
1
0
python,bash,pbs
0
20,234,550
0
2
0
false
0
0
I like to write data to sys.stderr sometimes for this sort of thing. It obviates the need to flush so much. But if you're generating output for piping sometimes, you remain better off with sys.stdout.
1
1
0
0
I write a python script in which there are several print statement. The printed information can help me to monitor the progress of the script. But when I qsub the bash script, which contains python my_script &> output, onto computing nodes, the output file contains nothing even when the script is running and printing something. The output file will contains the output when the script is done. So how can I get the output in real time through the output file when the script is running.
Output file contains nothing before script finishing
0
0
1
0
0
641
20,243,803
2013-11-27T13:28:00.000
0
0
0
0
0
python,django,sorting,django-tables2
0
21,063,484
0
1
0
true
1
0
In the matter of fact, this can't be done. if TemplateColumn name is based on name in model, sorting works fine. As far as I am concerned If you want present other data it is impossible.
1
2
0
0
Is it somehow possible, to add custom sort method to values generated using TemplateColumn? because on basic it tries to find column name in model and returns FieldError: Cannot resolve keyword u'coulmn_name' into field. Choices are: [all fields in model].
Django-tables2 Sorting TemplateColumn
1
1.2
1
0
0
448
20,271,881
2013-11-28T17:32:00.000
0
1
0
1
1
python,mercurial,mercurial-hook
1
20,836,549
0
1
0
true
0
0
I don't know exactly what happened, but it seams like it was not using the script because an exceptions somehow prohibited it from compiling to a pyc, and Mercurial somehow fetched the old version of that pyc file. Not too sure, but that's my best guess (as somehow noone else seems to have an idea and the Mercurial guys made it really clear they only answer stuff on their mailing list instead of SO.. how .. nice).
1
0
0
0
Ok, this is really weird. I have an old Mercurial 2.02. with python 2.6 on an old Ubuntu-something (I think 10.4). We are a windows shop, und push regularly, so I wanted kind of a review service. It absolutely worked on windows.. pretxnchangegroup referencing the python file on the drive, worked.. But I made the mistake to create the Mercurial hook on a new Mercurial 2.7, but then recognized the internal API changed, so I got back and fixed it, or tried to. I'm using windows, but need to deploy the hook to Linux, so I use WinSCP to copy the py file to my home directory. And then sudo cp it to the python 2.6 distro folder where the other hook file lie. I invoke the hook via the module pattern on the linux box: pretxnchangegroup.pushtest = python:mycompanyname.testcommit.exportpatches In the folder "mycompanyname" is the file testcommit.py and the function is named exportpatches. It works locally without a problem. The strange thing: It worked once, and kind of unstable: sometime it just says that the function "mycompanyname.testcommit.exportpatches" is not defined. And sometimes it just uses an old version of the hook (I see that because it gives an old exception message instead of the newer one). And I don't know how to get exception messages in python, so I'm lost there.. Second strange thing: these hook files also have a .pyc version, probably compiled, but my hook doesn't get such treatment. Is that autocompilation? If I try the directory approach to point to the file, I get a straight 500 internal error on push. I'm really lost and desperate by now, because the stuff has to work pretty soon, and I'm banging my head against the wall right now..
Mercurial hook: isn't recompiled after change?
0
1.2
1
0
0
44
20,283,021
2013-11-29T10:00:00.000
1
1
0
0
0
python,staruml
0
45,105,412
0
1
0
false
0
0
There is a simple possibility: Use PyCharm, a python IDE, which has an integrated UML generator (only in the pro version which is free for students).
1
3
0
0
Is there a way using StarUML for reverse engineering Python code to a class diagramm? In the StarUML docs, they say there are modules for language support, but I couldn't find any further information about where and how to install and use. Other UML tools I found didn't match my idea of how a diagramm should look like. I know it is a bit problematic generating class diagramms for python, because it's compiled to runtime and will probably change then. But I'm using Python to build my bachelor thesis and my Prof. loves UML. He really takes care of doing this correctly. Can anybody help me pls?
StarUML for Python
0
0.197375
1
0
0
2,332
20,291,176
2013-11-29T17:53:00.000
0
0
0
0
1
python,list,google-app-engine,jinja2
0
20,301,699
0
2
0
false
1
0
It sounds like you want to use itertools.product(list1, list2). This will create all combinations of list1 and list2. For example, if list1 = [1,2] and list2 = [1,2,3] then itertools.products(list1,list2) = [ (1,1),(2,1),(3,1),(2,1),(2,2),(2,3)]
1
0
0
0
I am using Jinja2 template in python for Google App Engine. I need to iterate through 2 lists list1 and list2 in the same loop in the html file. I tried using zip as described in some of the posts but it is not working. Something similar in C : for(i=0.j=0; I<len(list1) && j < len(list2) ; I++,j++) Can anyone suggest some ways to implement the same?
Iterate through 2 loops in GAE Python templates
0
0
1
0
0
86
20,293,848
2013-11-29T21:54:00.000
-1
0
1
1
0
python,windows
0
20,293,883
0
2
0
false
0
0
You can use os.chdir(target_directory) to change your program's working directory before starting the external application.
1
0
0
0
For example I know this method: os.system("cmd") but it starts console in the directory of the script or in the dir of the interpreter, is there a way to gain control of this issue ?
how to start external system application in python specifying startup directory?
1
-0.099668
1
0
0
46
20,295,446
2013-11-30T01:18:00.000
0
0
0
0
0
python,c,arrays,algorithm,sorting
0
20,295,483
0
6
0
false
0
0
Maybe use a nested for loop with the outside one looking at the ith point. then inside loop and calculate all the distances. After calculation use a native python sort for that row and then add it to the main 2d array.
1
0
1
0
Let's say I am given an array of n points(pair of coordinates). I want to generate a 2D array of points, where ith row has all elements sorted according to their distance from the ith point. There may be better and more efficient algorithms to get the final result, but for some reasons I want to do it by naive algorithm, i.e., brute-force. Also I don't want to write my own sorting function. In C language, one can use the qsort function, but it's compare function only takes two parameters whereas I will be needing to pass three parameters: the reference point and two other points to be compared. In Python too, one can use sorted function, but again, it's key function only takes one parameter, whereas in this case, I will need to pass two parameters. So how do I do it?
Custom sorting in for loop
0
0
1
0
0
202
20,296,712
2013-11-30T04:57:00.000
0
0
0
0
1
python,pygame,lines,pixels
0
20,298,727
0
2
1
false
0
1
Using float you should get all points without duplications - but you need int. Using int you always get duplications - int(0.1) == int(0.2) == int(0.3) == etc.. So you have to check if point is on your list.
1
0
0
0
Assuming I have a line with coordinates x1,y1 and x2,y2, and I know the length of the hypotenuse connecting those two points (thus also knowing the angle of rotation of the line through trig), if the line is 1 pixel thick how can I find every pixel on that line and store it to a list? I first proposed the simple vector calculation, stating with x1,y1 and performing line/z*math.cos(angle),line/z*math.sin(angle) (for x1 and y1 respectively) until I reached point x2,y2, but the problem with that is finding variable 'z' such that every single pixel is covered without duplicating pixels. So what would be the best way of calculating this?
How can I find every pixel on a line with pygame?
0
0
1
0
0
369
20,311,225
2013-12-01T10:36:00.000
3
0
1
0
1
python,python-2.7,argparse,command-line-arguments
0
20,314,797
0
1
0
false
0
0
Your best choice is to test for the presence of various combinations after parse_args and use parser.error to issue an argparse compatible error message. And write your own usage line. And make sure the defaults clearly indicate whether an option has been parsed or not. If you can change the -a and -e options to command names like cmda or build, you could use subparsers. In this case you might define a command_a subparser that accepts -b, -c, and -d, and another command_e subparser that has none of these. This is closes argparse comes to 'required together' groups of arguments. mutually exclusive groups can define something with a usage like [-a -b -c], but that just means -b cannot occur along with -a and -c. But there's nothing fancy about that mechanism. It just constructs a dictionary of such exclusions, and checks it each time it parses a new option. If there is a conflict it issues the error message and quits. It is not set up to handle fancy combinations, such as your (-e | agroup). Custom actions can also check for the absence or presence of non-default values in the namespace, much as you would after parsing. But doing so during parsing isn't any simpler. And it raises questions about order. Do you want to handle -b -c -a the same way as -a -c -b? Should -a check for the presence of the others, or should -b check that -a has already been parsed? Who checks for the presence, or absence of -e. The are a number of other stack questions about argparse groups, exclusive and inclusive, but I think these are the essential issues.
1
0
0
0
I am using python2.7 and argparse for my script. I am executing script as below: python2.7 script.py -a valuefora -b valueforb -c valueforc -d valueford Now what I want is that, if option -a is given, then only -b, -c, -d options should be asked. In addition to above, I also want to make this group -a -b -c -d as a EITHER OR for -e i.e. ([-a -b -c -d] | -e ) Please correct me anywhere I am wrong.
argparse: how to make group of options required only as group
0
0.53705
1
0
0
348
20,315,057
2013-12-01T17:29:00.000
3
0
0
0
0
python,xml,openerp,overwrite
0
20,322,373
0
1
0
true
1
0
yes you can. you just need to create a module with two files. one is __openerp__.py with correct dependency to the base modules and an xml file for updating the menu name.
1
2
0
0
I want to change an openerp module menu name. I know how to do it, i'ts actually pretty easy, but this one is a core module sale and i don't want to touch it's code, because of updates issues and stuff. So, i'll need to inherit this view and change it's name, from another module, can i do this without a module.py or a full __init__.py file? Just the openerp manifest file and an xml to overwrite it? Thanks in advance!
Change menu name openerp
0
1.2
1
0
0
325
20,324,828
2013-12-02T09:29:00.000
0
1
0
1
1
python,django,ubuntu
0
20,324,883
0
2
0
true
1
0
Sounds like an issue with your path - python not finding django becuase it doesnt know where to look for it. Look up issues regarding path and see if those help.
1
0
0
0
and thanks ahead of time. I am relatively new to Linux and am using Ubuntu 12.04.3. Basically, I've been messing around with some files trying to get Django to work. Well, I though I should do another install of Python2.7 for some reason. Stupidly, I manually installed it. Now when I open the Python shell and do 'import django', it can't be found. I just want to go back to using the Python that was on Ubuntu by default, or overwrite the one I installed manually with one using apt-get. However, I am unable to figure out how to do this nor have I found a question that could help me. Any help is much appreciated. I've been working on this for 6 hours now... --EDIT-- Ok well I'm just trying to go ahead and have the PYTHONPATH look in the right place. I've seen in other posts that you should do this in the ~/.profile file. I went into that file and added this line export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages "import django" is still coming up with "no module found" I tried doing "import os" and then "os.environ["PYTHONPATH"], which gave me: Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/UserDict.py", line 23, in getitem raise KeyError(key) KeyError: 'PYTHONPATH' As far as I can tell, this means that I do not have a PYTHONPATH variable set, but I am unsure as to what I am doing wrong. --ANOTHER EDIT-- As I am not a very reputable member, I am not allowed to answer my own question before 8 hours from my original question, so I am putting it as an update. Hey guys, thank you all for the quick responses and helpful tips. What I did was open a python shell and type: sys.path.append('/usr/local/lib/python2.7/dist-packages') and it worked! I should have done this from the beginning instead of trying to overwrite my manual Python installation. Once again, thank you all for the help. I feel so relieved now :)
I need to overwrite an existing Python installation in ubuntu 12.04.3
0
1.2
1
0
0
533
20,337,169
2013-12-02T20:27:00.000
1
0
1
0
0
python,import
0
20,337,294
0
1
0
true
0
0
Modules that are imported more than one are generally only initialized once and the namespace is introduced into the scope of the module. So in your example above there is one class fruit and the two classes that inherit from it and if you were to introduce 3 varieties of apple there would still only be one underlying fruit class. This is how professional packages do it. In other languages like C/C++ you need to use wards to prevent multiple imports python does if for you.
1
1
0
0
For instance, consider 3 modules namely "apple", "orange" and "fruit". Module "apple" imports "orange" and "fruit". Module "orange" imports "fruit" only. Since "fruit" is common for both, could this be done in a different way? Is this inefficient in terms of memory usage and speed? I wonder how this is done in professionally distributed packages. Say, if a standard library module (viz. httplib) is needed throughout various modules that has GUI code and other complicated stuff. importing this module in every GUI file would be impractical, wouldn't it?
Import in python, two modules sharing common resource
1
1.2
1
0
0
131
20,348,584
2013-12-03T10:28:00.000
0
0
0
0
0
python,mysql,sql,database,mysql-python
0
20,348,851
0
2
0
false
0
0
Not sure if I understand what it is you want to do. You want to match a value from a column from one table to a value from a column from another table? If you'd have the data in two tables in a database, you could make an inner join. Depending on how big the file is, you could use a manual comparison tool like WinMerge.
2
0
0
0
I have two databases (infact two database dump ... db1.sql and db2.sql) both database have only 1 table in each. in each table there are few columns (not equal number nor type) but 1 or 2 columns have same type and same value i just want to go through both databases and find a row from each table so that they both have one common value now from these two rows(one from each table) i would extract some information and would write into a file. I want efficient methods to do that PS: If you got my question please edit the title EDIT: I want to compare these two tables(database) by a column which have contact number as primary key. but the problem is one table has it is as an integer(big integer) and other table has it is as a string. now how could i inner-join them. basically i dont want to create another database, i simply want to store two columns from each table into a file so I guess i dont need inner-join. do i? e.g. in table-1 = 9876543210 in table-2 = "9876543210"
Compare two databases and find common value in a row
0
0
1
1
0
1,032
20,348,584
2013-12-03T10:28:00.000
0
0
0
0
0
python,mysql,sql,database,mysql-python
0
20,348,719
0
2
0
false
0
0
You can use Join with alias name.
2
0
0
0
I have two databases (infact two database dump ... db1.sql and db2.sql) both database have only 1 table in each. in each table there are few columns (not equal number nor type) but 1 or 2 columns have same type and same value i just want to go through both databases and find a row from each table so that they both have one common value now from these two rows(one from each table) i would extract some information and would write into a file. I want efficient methods to do that PS: If you got my question please edit the title EDIT: I want to compare these two tables(database) by a column which have contact number as primary key. but the problem is one table has it is as an integer(big integer) and other table has it is as a string. now how could i inner-join them. basically i dont want to create another database, i simply want to store two columns from each table into a file so I guess i dont need inner-join. do i? e.g. in table-1 = 9876543210 in table-2 = "9876543210"
Compare two databases and find common value in a row
0
0
1
1
0
1,032
20,355,886
2013-12-03T16:01:00.000
1
0
1
0
0
python,json
1
20,356,067
0
3
0
false
0
0
The problem is that the data structure has a list enclosing the dictionaries. If you have any control over the data source, that's the place to fix it. Otherwise, the best course is probably to post-process the data after parsing it to eliminate these extra list structures and merge the dictionaries in each list into a single dictionary. If you use an OrderedDict you can even retain the ordering of the items (which is probably why the list was used).
1
0
0
0
First, here is a sample JSON feed that I want to read in Python 2.7 with either simplejson or the built in JSON decoder. I am loading the .json file in Python and then searching for a key like "Apple" or "Orange" and when that key is found, I want to bring in the information for it like the types and quantities. Right now there is only 3 items, but I want to be able to search one that may have up to 1000 items. Here is the code: { "fruits": [ { "Apple": [ { "type": "Gala", "quant": 5 }, { "type": "Honeycrisp", "quant": 10 }, { "type": "Red Delicious", "quant": 4 } ] }, { "Banana": [ { "type": "Plantain", "quant": 5 } ] }, { "Orange": [ { "type": "Blood", "quant": 3 }, { "type": "Navel", "quant": 20 } ] } ] } My sample Python code is as follows: import simplejson as json # Open file fjson = open('/home/teg/projects/test/fruits.json', 'rb') f = json.loads(fjson.read()) fjson.close() # Search for fruit if 'Orange' in json.dumps(f): fruit = f['fruits']['Orange'] print(fruit) else: print('Orange does not exist') But whenever I test it out, it gives me this error: TypeError: list indices must be integers, not str Was it wrong to have me do a json.dumps and instead should I have just checked the JSON feed as-is from the standard json.loads? I am getting this TypeError because I am not specifying the list index, but what if I don't know the index of that fruit? Do I have to first search for a fruit and if it is there, get the index and then reference the index before the fruit like this? fruit = f['fruits'][2]['Orange'] If so, how would I get the index of that fruit if it is found so I could then pull in the information? If you think the JSON is in the wrong format as well and is causing this issue, then I am up for that suggestion as well. I'm stuck on this and any help you guys have would be great. :-)
Python: TypeError in referencing item in JSON feed
0
0.066568
1
0
0
65
20,389,368
2013-12-05T00:59:00.000
1
0
0
0
0
python,sqlalchemy
0
20,389,560
0
1
0
true
0
0
You can look at session.new, .dirty, and .deleted to see what objects will be committed, but that doesn't necessarily represent the number of rows, since those objects may set extra rows in a many-to-many association, polymorphic table, etc.
1
0
0
0
Is there a way to know how many rows were commited on the last commit on a SQLAlchemy Session? For instance, if I had just inserted 2 rows, I wish to know that there were 2 rows inserted, etc.
SQLAlchemy, how many rows were commited on last commit
0
1.2
1
1
0
193
20,403,387
2013-12-05T15:03:00.000
53
0
1
0
0
python,pypi
0
20,403,468
0
3
0
true
0
0
Login. Go to your packages. Check the "remove" checkbox for the particular package. Click "Remove" button.
1
58
0
1
How do I remove a package from Pypi? I uploaded a package to Pypi several months ago. The package is now obsolete and I'd like to formally remove it. I cannot find any documentation on how to remove my package.
How to remove a package from Pypi
0
1.2
1
0
0
27,292
20,406,998
2013-12-05T17:44:00.000
2
1
0
0
0
php,python,ruby
0
20,409,383
0
1
0
true
1
0
Language is irrelevant. Just put "short" operation in function (object, if it is complex) and use it from 2 places: web-code which needs "preview" will call it once and get its piece of data long-running background process will call it iteratively as much as needed and will store result of function in DB instead of returning it to user immediately Can be easily done in PHP. Long-running processeses are not a problem since 5.3
1
0
0
0
I have a web frontend which uses data from a task that must be run frequently in bulk (which takes more time than I'd like to use PHP for). The data can be stored in a database so I was planning on writing a Java application to run the task and use the database as a middleman to get the results of this task accessible to the web. Problem is, a "preview" of this data is needed occasionally. IE, sometimes the user needs to request a sample of the data (which can be computed quickly) to be generated on cue. This presents a real problem for me, this preview IS more suited for a language like PHP even though it's essentially the same task. It's just two cases, in case A there are real jobs from many users to be done so the task takes a sufficiently long time to complete (longer than a PHP request can hold), in case B it's a baby job for just one user ran on the spot which could be completed in PHP without issue. I don't want to write this code twice, it would make maintenance a nightmare so I kind of need to pick a language and stick with it. The frontend is designed but not implemented so I have an oppertunity to write the site in PHP, Ruby or Python if need be. I know PHP, so I would only consider switching to Python or Ruby if one of those languages offered a solution to this problem. but I know so little about these languages that I really cannot begin to know if they offer a solution without learning them (which I don't have the time for atm). In short, is there a non-hackish way to write short, quick event-driven code AND long-running repetitive code with Ruby on Rails or Python? If not do you have any ideas how to satifsy these two cases with either PHP or Java?
PHP / Python / Ruby - Long running tasks with short previews
1
1.2
1
0
0
81
20,411,315
2013-12-05T21:38:00.000
0
0
0
0
0
python,qt,pyqt4
0
20,411,550
0
1
0
false
0
1
In the handler of the button-click in the first window, instantiate the second window and invoke its show-method, and then close (emit the close-signal to) the first window.
1
0
0
0
I have two pyqt files that I made in qt4 designer. I put them both in a directory and created a file outside the directory, which I imported them with. The first file is a window with a button, that when clicked, should close the first window, and open the second window. I can import them, and launch them both at the same time, but I can't figure out how to have the button in the first window affect the other, yet alone have it close itself and spawn the other.
How to tie two windows together in pyqt4
0
0
1
0
0
150
20,415,414
2013-12-06T03:29:00.000
5
0
0
0
0
python,pandas,dataframe
0
20,415,698
0
5
0
false
0
0
What have you tried? You could sort with s.sort() and then call s.head(3).index and s.tail(3).index.
1
4
1
0
How can I find the index of the 3 smallest and 3 largest values in a column in my pandas dataframe? I saw ways to find max and min, but none to get the 3.
python pandas 3 smallest & 3 largest values
0
0.197375
1
0
0
7,247
20,421,965
2013-12-06T10:47:00.000
0
0
0
1
1
python,google-app-engine,blob,google-cloud-datastore
0
20,424,484
0
1
0
false
1
0
Datastore has a limit on the size of objects stored there, thats why all examples and documentation say to use the blobstore or cloud storage. Do that.
1
0
0
0
Just wondering how to store files in the google app engine datastore. There are lots of examples on the internet, but they are using blobstore I have tried importing db.BlobProperty, but when i put() the data it shows up as a <Blob> i think. It appears like there is no data Similar to None for a string Are there any examples of using the Datastore to store files Or can anyone point me in the right direction I am new to programming, so not to complex, but I have a good hang of Python, just not an expert yet. Thanks for any help
How do I store files in googleappengine datastore
0
0
1
1
0
71
20,427,217
2013-12-06T15:09:00.000
1
1
0
0
1
python,web2py
0
20,437,241
0
1
0
true
1
0
Look at section 4.17.1 of the web2py manual (or Google "web2py cron"). You can run a script on startup of web2py by registering it in the crontab file as: "@reboot web2py *scripts/myscript.py" web2py should be the username that it will run as, which should be the same as what web2py runs as. In my setup I have a user named 'web2py' to run the app. The asterix before scripts/myscript.py indicates that you want to run the script in the web2py environment. Keep in mind that you run the risk of locking issues if your script is trying to use the database at the same time as the normal web2py process.
1
0
0
0
I need a launch script which has access to "db" and other web2py modules. This script must be running constantly. I know that Web2py has launch parameters from which you can run python files in the web2py enviroment, but i don't know how that works. Can this parameter solve my problem and if so, how do I go about it? Thanks!
Web2py launch script
0
1.2
1
0
0
1,158
20,433,712
2013-12-06T21:16:00.000
0
0
0
1
0
python,development-environment,vagrant
0
21,195,137
0
1
0
false
0
0
In most IDE you can add "library" path which are outside the project so that your code completion etc works. About the traceback, I'm unfamiliar with python but this sounds like issue that are resolved by "mapping" paths between servers and dev machine. This is generally the reason why #2 is often the way to go (Except when you have a team willing to do #1).
1
5
0
0
I'm investigating ways to add vagrant to my development environment. I do most of my web development in python, and I'm interested in python-related specifics, however the question is more general. I like the idea of having all development-related stuff isolated in virtual machine, but I haven't yet discovered an effective way to work with it. Basically, I see 3 ways to set it up: Have all services (such as database server, MQ, etc) as well as an application under development to run in VM. Developer would ssh to VM and edit sources there, run app, tests, etc, all in an ssh terminal. Same as 1), but edit sources on host machine in mapped directory with normal GUI editor. Run application and tests on vagrant via ssh. This seems to be most popular way to use vagrant. Host only external services in VM. Install app dependencies into virtualenv on host machine and run app and tests from there. All of these approaches have their own flaws: Developing in text console is just too inconvenient, and this is the show-stopper for me. While I'm experienced ViM user and could live with it, I can't recommend this approach to anyone used to work in any graphical IDE. You can develop with your familiar tools, but you cannot use autocompletion, since all python libs are installed in VM. Your tracebacks will point to non-local files. You will not be able to open library sources in your editor, ctags will not work. Losing most of "isolation" feature: you have to install all compilers, *-dev libraries yourself to install python dependencies and run an app. It is pretty easy on linux, but it might be much harder to set them all up on OSX and on Windows it is next to impossible I guess. So, the question is: is there any remedy for problems of 2nd and 3rd approaches? More specifically, how is it possible to create an isolated and easily replicatable environment, and yet enjoy all the comfort of development on host machine?
Using vagrant as part of development environment
1
0
1
0
0
1,504
20,455,129
2013-12-08T15:29:00.000
1
0
0
0
0
python,mysql,latitude-longitude
0
20,455,724
0
1
0
true
0
0
Load B into a python list and for each calculate maxlat, minlat, maxlong, minlong that everything outside of the box is definitely outside of your radius, if your radius is in nautical miles and lat/long in degrees. You can then raise an SQL query for points meeting criteria of minlat < lat < maxlat and minlong < long < maxlong. The resulting points can then be checked for exact distance and added to the in range list if they are in range. I would suggest doing this in multiple processes.
1
0
0
0
Problem I have a list of ~5000 locations with latitude and longitude coordinates called A, and a separate subset of this list called B. I want to find all locations from A that are within n miles of any of the locations in B. Structure All of this data is stored in a mysql database, and requested via a python script. Approach My current approach is to iterate through all locations in B, and request locations within n miles of each location, adding them to the list if they don't exist yet. This works, but in the worst case, it takes a significant amount of time, and is quite inefficient. I feel like there has to be a better way, but I am at a loss as for how to do it. Ideas Load all locations into a list in python, and calculate distances there. This would reduce the number of mysql queries, and likely speed up the operation. It would still be slow though.
Finding Locations with n Miles of Existing Locations
0
1.2
1
1
0
71
20,458,011
2013-12-08T19:35:00.000
5
0
1
0
0
python,python-2.7,python-3.3,python-2to3
0
47,106,899
0
9
0
false
0
0
To convert all python 2 files in a directory to 3, you simply could run $ C:\Program Files\Python\Tools\Scripts\2to3.py -w -n. inside the directory that you want to translate. It would skip all the non .py files anyway, and convert the rest. note: remove the -n flag, if you want the backup file too.
3
69
0
0
I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.
How to use 2to3 properly for python?
0
0.110656
1
0
0
73,248
20,458,011
2013-12-08T19:35:00.000
1
0
1
0
0
python,python-2.7,python-3.3,python-2to3
0
65,057,406
0
9
0
false
0
0
Running it is very simple! I am going to consider you already have it installed and explain step-by-step how to proceed after that: Open terminal (or cmd for win users) inside the main folder containing the files you want to convert e.g. C:\Users\{your_username}\Desktop\python2folder Type python {your_2to3.py_install_directory} -w .\ e.g. in my case (win10) it would be: python C:"\Program Files"\Python39\Tools\scripts\2to3.py -w .\ This is going to make the program scan the entire directory (and sub directories as well) and automatically convert everything that is written in Python2 to Python3. -w flag makes the script apply the changes creating new converted files. So remove this you'd like to just scan and see what needs conversion (but without actually doing anything) If you'd like to convert just one file instead of entire folders simply substitute .\ for python2_file_name.py: e.g. python {your_2to3.py directory} -w python2_file_name.py Also, by default it creates a .bak file for everything it converts. It is highly advised to keep it this way since any conversion is prone to errors but if you'd like to disable the automatic backup you could also add the -n flag. e.g. python C:"\Program Files"\Python39\Tools\scripts\2to3.py -w -n python2_file_name.py 3.Done!
3
69
0
0
I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.
How to use 2to3 properly for python?
0
0.022219
1
0
0
73,248
20,458,011
2013-12-08T19:35:00.000
-2
0
1
0
0
python,python-2.7,python-3.3,python-2to3
0
48,277,515
0
9
0
false
0
0
The python 2to3.py file is mostly found in the directory C:/Program Files/Python/Tools/scripts if you already have python installed. I have python 3.6 and 2to3 is in the directory C:/Program Files/Python36/Tools/scripts. To convert a certain python 2 code to python 3, go to your command promt, change the directory to C:/Program Files/Python36/Tools/scripts where the 2to3 file is found. Then add the following command: python 2to3.py -w (directory to your script). eg. C:\Program Files\Python36\Tools\scripts> python 2to3.py -w C:Users\Iykes\desktop\test.py. the '-w' here ensures a backup file for your file is created.
3
69
0
0
I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.
How to use 2to3 properly for python?
0
-0.044415
1
0
0
73,248
20,467,107
2013-12-09T09:23:00.000
1
0
1
0
0
python,urllib2,urllib,urllib3
0
20,467,364
0
3
0
false
0
0
Personally I avoid to use third-party library when possible, so I can reduce the dependencies' list and improve portability. urllib and urllib2 are not mutually exclusive and are often mixed in the same project.
2
9
0
0
as we know, python has two built-in url lib: urllib urllib2 and a third-party lib: urllib3 if my requirement is only to request a API by GET method, assume it return a JSON string. which lib I should use? do they have some duplicated functions? if the urllib can implement my require, but after if my requirements get more and more complicated, the urllib can not fit my function, I should import another lib at that time, but I really want to import only one lib, because I think import all of them can make me confused, I think the method between them are totally different. so now I am confused which lib I should use, I prefer urllib3, I think it can fit my requirement all time, how do you think?
Which urllib I should choose?
0
0.066568
1
0
1
22,979
20,467,107
2013-12-09T09:23:00.000
10
0
1
0
0
python,urllib2,urllib,urllib3
0
20,467,287
0
3
0
true
0
0
As Alexander says in the comments, use requests. That's all you need.
2
9
0
0
as we know, python has two built-in url lib: urllib urllib2 and a third-party lib: urllib3 if my requirement is only to request a API by GET method, assume it return a JSON string. which lib I should use? do they have some duplicated functions? if the urllib can implement my require, but after if my requirements get more and more complicated, the urllib can not fit my function, I should import another lib at that time, but I really want to import only one lib, because I think import all of them can make me confused, I think the method between them are totally different. so now I am confused which lib I should use, I prefer urllib3, I think it can fit my requirement all time, how do you think?
Which urllib I should choose?
0
1.2
1
0
1
22,979
20,476,969
2013-12-09T17:37:00.000
0
0
1
0
0
python,list,python-3.x
0
20,477,231
0
8
0
false
0
0
Even numbers are divisible by 2. Odd numbers are not. len(X) will get the length of X If the length of X is divisible by 2, then it is an Even number If the length of X is not divisible by 2 then it is an Odd Number len(X)%2 returns the "remainder" of a division problem for example 5%2 will return 1 which is NOT zero, (because 5 divided by 2 is 2 with a remainder of 1), therefore it is not even. Same thing as 6%4 which would return a 2, because 6 divided by 4 is 1 with a remainder of 2. so len(X)%2 where X is your list, will return either a 1, indicating it is Odd, or a 0 indicating it is Even.
1
2
0
0
How can I find out if there is even, or odd, number of elements in an arbitrary list. I tried list.index() to get all of the indices... but I still don't know how I can tell the program what is an even and what is an odd number.
How to know if a list has an even or odd number of elements
0
0
1
0
0
14,621
20,489,514
2013-12-10T08:32:00.000
2
1
1
0
0
python,integration-testing,setup.py
0
20,489,835
0
2
0
false
0
0
If you really want isolation instead just doing python setup.py install in virtualenv. Then use virtualbox and install some free linux os in it. Take a snapshot of the machine after the install so you can revert easily with one click to the starting point at any time and try python setup.py install there.
1
8
0
0
I have a pretty big Python package I've written, about 3500 statements, with a robust unit and acceptance test suite. I feel quite confident about the quality of the code itself, but I'm uneasy about the install process going smoothly for users of the package as I don't know how to reliably test the install in an appropriately isolated environment, short of something like keeping a spare machine around and re-imaging it with a fresh OS install for each test run. I suspect using virtualenv in the right way might provide a proper test fixture for testing installation, but after extended web searches have uncovered no helpful guidance. How can I effectively test my setup.py and other installation bits on my development machine?
How do I test the setup.py for my package?
0
0.197375
1
0
0
1,343
20,492,587
2013-12-10T10:57:00.000
0
0
0
0
0
python-2.7,turbogears2
0
20,525,832
0
1
0
true
0
0
tgext.datahelpers uploads files on disk inside the public/attachments directory (this can be change with tg.config['attachments_path']). So your file is already stored on disk, only the file metadata, like the URL, filename, thumbnail_url and so on are stored on database in JSON format
1
1
0
0
how to do file uploading in turbogears 2.3.1? I am using CrudRestController and tgext.datahelpers and it is uploading the file in the sqlite3 database but in an unknown format. I want to make a copy of the uploaded file in the hard drive. My query is how to ensure that when user uploads a file, it is loaded both in the database and the hard drive. (Thank you for suggestions)
file upload turbogears 2.3.1
0
1.2
1
1
0
226
20,500,717
2013-12-10T17:05:00.000
3
0
1
0
0
python
0
20,500,806
0
1
0
true
0
0
Context managers all have __enter__() and __exit__() methods, so checking to see if those attributes exist and that they have __call__ attributes will work almost all the time. But yeah, read the code and/or documentation for the class first.
1
4
0
0
The only time I ever use the with keyword is when reading and writing files, mostly because that's the only case I actually know that I can use it. I can imagine there are numerous instances where I preferably could have used with, but didn't know a class or method accepted it. So, how do I detect instances where the with keyword can be used?
How can I easily find out if a Python class accepts the with keyword?
0
1.2
1
0
0
44
20,502,766
2013-12-10T18:45:00.000
-3
0
0
0
1
python,angle,turtle-graphics
0
49,330,538
0
2
0
false
0
1
turtle.right(90) this will turn the turtle 90
1
6
0
0
I'm creating a function that will cause a giraffe to move in a certain direction and distance (don't ask). If the user types "west" in the parameters, the turtle should move west however the direction is. But the turtle's angle changes every time, I can't fix a value for my turtle to turn to go a certain direction. I need to set the angle to, say, 90 so that it can move East. I can't find useful functions for this purpose. I tried to use Pen().degrees(90) but that didn't work. Does anyone know how I can do this?
Setting the angle of a turtle in Python
0
-0.291313
1
0
0
18,276
20,507,907
2013-12-11T00:00:00.000
4
0
1
1
0
python,windows,shell,startup
0
20,508,067
0
2
0
true
0
0
Create a batch file with the line start C:\python27\python.exe D:your_program_location\your_program.py' Drag the batch file from desktop to "Start - All Programs - Startup". That should do the trick.
2
0
0
0
I have made a program that takes infrared values serially, transmits them them to another program(the one im having trouble with), and uses the win32 python api to react to a matched value. It all works, but I need this program to run on the startup of my computer. It uses the IDLE python shell to run, and I need to open/run the file directly from that program. Is there any way to do this? I can't just put a shortcut into the startup directory because its an unrecognized file, and it needs to be run, not just opened. Any help would be great, thanks!
how to Start python shell program on windows 7 startup?
0
1.2
1
0
0
6,240
20,507,907
2013-12-11T00:00:00.000
0
0
1
1
0
python,windows,shell,startup
0
20,508,698
0
2
0
false
0
0
It sounds like your actual problem is just that you didn't put the right extension on the file. Just rename it to, e.g., script.py, or script.pyw, and, unless you've changed the settings from the default, that should open the file with the command-line or windowed Python launcher, which will just run it. If you've changed your settings so .py files open in IDLE instead of in the Python launcher… is there a reason you want those weird settings? If not, just undo it.
2
0
0
0
I have made a program that takes infrared values serially, transmits them them to another program(the one im having trouble with), and uses the win32 python api to react to a matched value. It all works, but I need this program to run on the startup of my computer. It uses the IDLE python shell to run, and I need to open/run the file directly from that program. Is there any way to do this? I can't just put a shortcut into the startup directory because its an unrecognized file, and it needs to be run, not just opened. Any help would be great, thanks!
how to Start python shell program on windows 7 startup?
0
0
1
0
0
6,240
20,509,103
2013-12-11T01:54:00.000
1
0
0
0
0
python,random
0
20,509,223
0
2
0
false
0
0
To generate retrieve the path of a random image in a folder img_folder, it's not too difficult. You can use img_path_array = os.listdir('.../img_folder'). Randomly generate an integer between 0 and len(img_path_array) using random_index = randrange(len(img_path_array)) (import random to use this function), and gain access to the random file url by calling img_path_array[random_index].
1
1
1
0
I really appreciate any responses. I am thoroughly confused and never knew this experiment design/builder software was so complicated! I am a fast learner, but still a newbie so please be patient. Yes I have googled the answers for my question but no answers to similar questions seem to work. I have an experiment, there are 8 conditions, each condition needs to show 1 image, chosen at random from a folder of similar images. Each trial needs to be different (so each participant sits a differently ordered set of conditions) AND each condition's selected image will be different. So; Condition- Image A - 1 to 140 B - 1 to 80 etc.. Recording data is not a problem as this can be done by hand, but I just need the images to be randomly selected from a pre-defined group. I have tried using code to randomise and shuffle the order, but have got nowhere. Please help, Tom
how to randomise the image shown in a sketchpad
0
0.099668
1
0
0
65
20,528,082
2013-12-11T19:19:00.000
1
0
0
0
0
python,validation,user-interface,checkbox,tkinter
0
20,528,169
0
2
0
false
0
1
Don't use checkboxes; use radoibuttons instead. The behavior of checkboxes and radiobuttons is well established -- checkboxes allow you to select N of N choices, radiobuttons are designed to allow you to select exactly 1 of N. Don't violate this design pattern or your users will be confused. To make radiobuttons work, create a single StringVar and associate it with two or more radiobuttons. All of the radiobuttons that share the same variable will work as a set, allowing only one to be selected.
1
0
0
0
I am trying to create a multiple choice quiz in Tkinter. Each question has between 2-4 different answers all displayed as checkboxes, how do I ensure the user can only tick one check box and not all of them? Thanks
Checkbox validation: how do i ensure user can only tick one box only?
0
0.099668
1
0
0
1,562
20,529,878
2013-12-11T21:04:00.000
5
0
0
0
0
python,python-3.x,time-complexity
0
20,531,306
0
3
0
false
0
0
This is too long for a comment: in CPython, a yield passes its result to the immediate caller, not directly to the ultimate consumer of the result. So, if you have recursion going R levels deep, a chain of yields at each level delivering a result back up the call stack to the ultimate consumer takes O(R) time. It also takes O(R) time to resume the R levels of recursive call to get back to the lowest level where the first yield occurred. So each result yield'ed by walk() takes time proportional to the level in the directory tree at which the result is first yield'ed. That's the theoretical ;-) truth. In practice, however, this makes approximately no difference unless the recursion is very deep. That's because the chain of yields, and the chain of generator resumptions, occurs "at C speed". In other words, it does take O(R) time, but the constant factor is so small most programs never notice this. This is especially true of recursive generators like walk(), which almost never recurse deeply. Who has a directory tree nested 100 levels? Nope, me neither ;-)
2
3
0
0
I've to calculate the time-complexity of an algorithm, but in it I'm calling os.walk which I can't consider as a single operation but many. The sources of os.walk left me confused as the filetree may be ordered in many ways (1.000.000 files in a folder or a file per folder and 1.000.000 folders. I'm not an expert on time-complexities, I can't be sure on what I should consider as only an operation or many, so this left me stuck. Don't count the simlink flag, which I assume set to false to ignore them. PD: I found the sources of os.walk in the Komodo IDE, but I wouldn't know how to find them as the javadocs.
Time complexity of os.walk in Python
0
0.321513
1
0
0
2,735
20,529,878
2013-12-11T21:04:00.000
2
0
0
0
0
python,python-3.x,time-complexity
0
20,530,026
0
3
0
false
0
0
os.walk (unless you prune it, or have symlink issues) guarantees to list each directory in the subtree exactly once. So, if you assume that listing a directory is linear on the number of entries in the directory,* then if there are N total directory entries in your subtree, os.walk will take O(N) time. Or, if you want the time for walk to produce each value (the root, dirnames, filenames tuple): if those N directory entries are split among M subdirectories, then each of the M iterations takes amortized O(N/M) time. * Really, that's up to your OS, C library, and filesystem not Python, and it can be much worse than O(N) for older filesystems… but let's ignore that.
2
3
0
0
I've to calculate the time-complexity of an algorithm, but in it I'm calling os.walk which I can't consider as a single operation but many. The sources of os.walk left me confused as the filetree may be ordered in many ways (1.000.000 files in a folder or a file per folder and 1.000.000 folders. I'm not an expert on time-complexities, I can't be sure on what I should consider as only an operation or many, so this left me stuck. Don't count the simlink flag, which I assume set to false to ignore them. PD: I found the sources of os.walk in the Komodo IDE, but I wouldn't know how to find them as the javadocs.
Time complexity of os.walk in Python
0
0.132549
1
0
0
2,735
20,543,708
2013-12-12T12:34:00.000
0
0
1
0
0
python,security,token,m2crypto,pkcs#11
0
41,831,467
0
1
0
false
0
0
using PKCS#11, the only way to store 'home made' data, it through the use of a CKO_DATA object type. Like any object, it can be persistent on the token (not lost when the token is powered off) or it can be a memory object (lost when the session to the token is closed). To create a CKO_DATA object is similar to any other object creation: open a r/w session on the slot if the object is to be protected by user authentication (CKU_USER) then Login as user create the object template with mandatory attributes such as CKA_CLASS etc. (refer to the PKCS#11 specifications for details) set the CKA_TOKEN to TRUE if the object is to be persistent, or FALSE if it is a memory object set the CKA_PRIVATE to TRUE* if you want this object to be read/writen only upon successfull user authentication or set it to **FALSE if anybody can access it. set a CKA_LABEL and CKA_APPLICATION attributes with values you want to help you find the object next time set the CKA_VALUE attribute to the value you want (your integer) Call C_CreateObject, using this template will create the desired object. HTH,
1
2
0
0
Is it possible to save a value in a security token memory by using PyKCS11 and M2Crypto? I need to save an integer to token memory, so that the value can be carried out with the token I know how to create objects, but is it possible to create attributes in a token, so whenever I read that attribute I will know the status of that token.
How to save a temporary value in a security token?
1
0
1
0
0
203
20,547,049
2013-12-12T15:08:00.000
0
0
1
0
1
python,debugging,console,interactive
1
34,922,501
1
6
0
true
0
0
You can do all this in the iPython Notebook. Use the magic command %pdb to stop on error.
1
9
0
0
I've recently moved from Matlab to Python. Python is a much better language (from the point of view of a computer scientist), but Python IDEs all seem to lack one important thing: A proper interactive debugger. I'm looking for: The ability to set breakpoints graphically by clicking next to a line of code in the editor. The ability to run ANY CODE while stopped in the debugger, including calling functions from my code, showing new windows, playing audio, etc. When an error occurs, the debugger should automatically open an interactive console at the error line. Once done with the interactive console, you can resume normal execution. Matlab has all these features and they work incredibly well, but I can't find them anywhere in Python tools. I've tried: PyCharm: the interactive console is clunky, often fails to appear, and crashes all the time (I've tried several different versions and OSs). IPython: can't set breakpoints -Launching a Python console programatically: you have to stop your code, insert an extra line of code, and run again from the beginning to do this. Plus, you can't access functions already imported without re-importing them. Being able to debug and fix problems THE FIRST TIME THEY APPEAR is very important to me, as I work in programs that often take dozens of minutes to re-run (computational neuroscience). CONCLUSION: there is NO way to do all of these in Python at the moment. Let us hope that PyLab development accelerates.
In Python, how do I debug with an interactive command line (and visual breakpoints?)
0
1.2
1
0
0
4,947
20,557,627
2013-12-13T01:36:00.000
-1
0
1
0
0
python
0
20,557,641
0
2
0
false
0
0
I don't recommend trying this in batch file. Learning the basics of a scripting language such as Python or Perl is much better for this type of work.
1
0
0
0
I have a list of fruits example: "banana", "apple", "grape", "strawberry" and I want to create files with the text: "This fruit is %fruit name%, its delicious" and save as %fruit name%.fruits how i do that? cam be in any language
create files, with a template and a list of name and save on files
0
-0.099668
1
0
0
41
20,574,073
2013-12-13T19:04:00.000
0
0
1
0
0
python,django,debian-packaging
0
20,574,224
0
1
0
false
1
0
How to install not only Django project, but also Python and Django with it? What and where and how should I write the script? If you created a deb file, as it gets interpreted, you should write the python dependency in the debian/control file. This project demand diffrent additions, such as grappelli, tinymce, filebrowser. Should I do anything with it? If this packages are in any repository (or your repository) then you can either, put them as recommendation or as suggestion in the control file.
1
0
0
0
I have a Django project needed to be installed in Debian. I make packages via stdeb. I do not understand two things, on which I can`t find answers: How to install not only Django project, but also Python and Django with it? What and where and how should I write the script? This project demand different additions, such as grappelli, tinymce, filebrowser. Should I do anything with it?
Distribution Python package to Debian package with installing additional things
0
0
1
0
0
98
20,587,888
2013-12-14T20:26:00.000
0
0
0
0
0
python,sql,postgresql,sqlalchemy
0
20,589,295
0
1
1
true
0
0
You could use a schema change management tool like liquibase. Normally this is used to keep your database schema in source control, and apply patches to update your schema. You can also use liquibase to load data from CSV files. So you could add a startup.csv file in liquibase that would be run the first time you run liquibase against your database. You can also have it run any time, and will merge data in the CSV with the database.
1
1
0
0
I tend to start projects that are far beyond what I am capable of doing, bad habit or a good way to force myself to learn, I don't know. Anyway, this project uses a postgresql database, python and sqlalchemy. I am slowly learning everything from sql to sqlalchemy and python. I have started to figure out models and the declarative approach, but I am wondering: what is the easiest way to populate the database with data that needs to be there from the beginning, such as an admin user for my project? How is this usually done? Edit: Perhaps this question was worder in a bad way. What I wanted to know was the possible ways to insert initial data in my database, I tried using sqlalchemy and checking if every item existed or not, if not, insert it. This seemed tedious and can't be the way to go if there is a lot of initial data. I am a beginner at this and what better way to learn is there than to ask the people who do this regularly how they do it? Perhaps not a good fit for a question on stackoverflow, sorry.
Sqlalchemy, python, easiest way to populate database with data
0
1.2
1
1
0
995
20,605,544
2013-12-16T07:31:00.000
2
1
1
0
0
python,amazon-web-services,amazon-elastic-beanstalk
0
20,607,574
0
1
0
true
0
0
by including it in the requirements.txt, you can include only the packages you are calling. Pip then takes care of installing the dependencies and checking the versions. This has the additional advantage of when you are changing or upgrading your project, you can specify a new version of the library you are using and all the dependent libraries will also be updated.
1
1
0
0
I was wanting to use some non-standard python packages in my project and was wondering how to add them. What is the benefit of using the AWS eb config files (.ebextensions and requirements.txt) rather than just downloading and including the package in my actual project under a lib directory like you would with a java application?
Adding external packages to elastic beanstalk python app
0
1.2
1
0
0
289
20,614,349
2013-12-16T15:20:00.000
2
0
1
0
1
c++,python,parallel-processing,scheduling,directed-acyclic-graphs
0
20,619,386
0
1
0
true
0
0
This is a pretty common problem. It also shows up in hardware design. There has been a lot of work on algorithms to solve it. If you are going to write something yourself, start by checking out "Hu's Algorithm". If you just want a solution, these functions are built into architectural synthesis programs. Look at the Wikipedia pages on high level synthesis and logic synthesis. There are several professional tools that can handle this, if you can get access to them through school or work. There are university programs you can often get for free that can also handle this problem. I'm not up-to-date on what is currently available. An very old one is MIS II from Berkeley. It's scripting language was Tcl, not Python.
1
4
0
0
I have a graph of the dependencies of all tasks, and the costs of each task. Now I want to calculate a scheduling for a given amount of CPUs. I've found many papers on scheduling algorithms, optimal schedulers seem to be too expensive for my problem size (around 100 nodes) as it's an NP-hard problem. I'd settle for a heuristic, preferably one that has a bound how close it gets to the optimum. My problem now is: do I really have to code it myself?? This should have been solved many times before, it can be easily applied to project management, maybe there something exists? If you happen to know a library in python that'd be perfect or the next best thing would be C++, otherwise i'd settle for anything else.
finding static scheduling of DAG for multiprocessors - library?
0
1.2
1
0
0
606
20,634,301
2013-12-17T12:35:00.000
1
0
1
0
0
python,blender-2.67
0
20,701,809
0
1
0
true
0
0
I finally got the solution to the problem. 1. Invoke blender through command line blender.exe --background --python yourFile.py 2. In your python file, you could use the modules provided by blender such as import_ply (....Blender/2.68/scripts/addons/import_ply), etc. Just go through the module and you will be able to use the function written inside and manage to write code according to your need.
1
2
0
0
I want to apply a modifier to large number of meshes stored in different .ply files. I wish to do this through command line so that the process can be automated. I know the basic of blender python API like how to write the modifier in python. But that required me to first import .ply file in blender using UI and then run my python script. However, I want to automate the process of loading ply file, do the required operations and save back the result in ply format so that all the files can be processed one by one with minimum manual work.
How can I load a .ply file in blender-2.68 and apply modifier to it through command line/script?
0
1.2
1
0
0
1,414
20,637,439
2013-12-17T14:59:00.000
-2
0
0
0
0
python,pandas,csv,readfile
0
55,944,660
0
6
0
false
0
0
skip[1] will skip second line, not the first one.
1
121
1
0
I'm trying to import a .csv file using pandas.read_csv(), however, I don't want to import the 2nd row of the data file (the row with index = 1 for 0-indexing). I can't see how not to import it because the arguments used with the command seem ambiguous: From the pandas website: skiprows : list-like or integer Row numbers to skip (0-indexed) or number of rows to skip (int) at the start of the file." If I put skiprows=1 in the arguments, how does it know whether to skip the first row or skip the row with index 1?
Skip rows during csv import pandas
0
-0.066568
1
0
0
269,629
20,660,579
2013-12-18T14:17:00.000
0
0
1
0
0
python,regex,pyqt4,qregexp
0
32,671,451
0
2
0
false
0
0
Just to post an answer on this side of things... In most cases I've played with, the DOTALL "(.*?)" approach doesn't seem to match anything when it comes to QRegExp(). However, here's something I use that works in almost all my cases for matching triple-quoted strings: single: "[^#][uUbB]?[rR]?(''')[^']*(''')" double: '[^#][uUbB]?[rR]?(""")[^"]*(""")' The only cases that don't work: ''' ' ''' and """ " """. best thing I could find for now... EDIT: if I don't have those as the stop characters, it continues to match through the rest of the document.
1
1
0
0
Recently I've been working on a PyQt program. In the beginning I used python re module to process the regex, but the transformation between python string and QString makes me confused. So I tried to change QRegExp. However, I want to use the IGNORECASE, MULTILINE, DOTALL of the python re. I've found the QRegExp.setCaseSensitivity() to replace the re.I, but I can't find the rest two features. Can anybody help? Or tell me how to transform the QString to python string? Both the regex pattern and data are input by the user, so their types are QString.
Can QRegExp do MULTILINE and DOTALL match?
0
0
1
0
0
607
20,661,142
2013-12-18T14:44:00.000
7
0
0
0
0
python,machine-learning,scipy,k-means
0
20,661,301
0
1
0
false
0
0
Based on the documentation, it seems kmeans2 is the standard k-means algorithm and runs until converging to a local optimum - and allows you to change the seed initialization. The kmeans function will terminate early based on a lack of change, so it may not even reach a local optimum. Further, the goal of it is to generate a codebook to map feature vectors to. The codebook itself is not necessarily generated from the stoping point, but will use the iteration that had the lowest "distortion" to generate the codebook. This method will also run kmeans multiple times. The documentation goes into more specifics. If you just want to run k-means as an algorithm, pick kmeans2. If you just want a codebook, pick kmeans.
1
10
1
0
I am new to machine learning and wondering the difference between kmeans and kmeans2 in scipy. According to the doc both of them are using the 'k-means' algorithm, but how to choose them?
What's the difference between kmeans and kmeans2 in scipy?
0
1
1
0
0
3,357
20,666,947
2013-12-18T19:40:00.000
1
0
0
0
0
android,python-2.7,kivy
0
22,365,294
0
1
0
true
0
1
There is no way to do it from the build.py. However, you can change manually the templates/AndroidManifest.xml.tmpl and adapt it for your needs.
1
1
0
0
Is there a way to establish a "supports-screens" kind of configuration to make my application available only for normal and large screens android devices.is there a way to do this with the build.py script?(i have bets on --intent-filters option but not sure how it might be used)
screen support in kivy set to normal and large screens
1
1.2
1
0
0
84
20,684,509
2013-12-19T14:40:00.000
1
0
0
0
0
python,python-3.x
0
20,714,626
0
1
0
false
0
0
OK, after numerous hours on google I found out that .scd's are basically .zip's with a 0% compression rate. Try using the built in zipfile module on your file as though it were a .zip.
1
2
0
0
I am trying to make a program with python that downloads a large .scd file, unpacks it, and then installs it. It is not at all difficult for me to download it or install it, (which is pretty much just using urllib and moving a few files around) but unpacking it seems to be a problem. After a couple hours of Googling I can't seem to find any modules for Python capable of opening .scd archives. One idea is to try to convert is to a .zip file with Python, replace the .scd with that, and the just use zipfile.extractall(). I am fine with this if someone can tell me how to do the conversion. The conversion/extraction MUST be automated. EDIT: It is OK with me if a use 3rd party software, but I still would like the following things: the process must be totally automated, (the user does not have to hit an extract button or anything along those lines) the 3rd party software must have a license that allows me to use it as part of my Python program, (and distribute it as part of my program's package to the general public) and the software is compatible with Windows.
Open .scd files in python?
0
0.197375
1
0
0
459
20,693,168
2013-12-19T22:45:00.000
0
0
0
0
0
python,google-sheets
0
50,629,830
0
3
0
false
1
0
Yes, it is possible and this is how I am personally doing it so. search for "doGet" and "doPost(e)
1
0
0
0
I dont even know if this is possible. But if it is, can someone give me the broadstrokes on how I can use a Python script to populate a Google spreadsheet? I want to scrape data from a web site and dump it into a google spreadsheet. I can imagine what the Python looks like (scrapy, etc). But does the language support writing to Google Drive? Can I kick off the script within the spreadsheet itself or would it have to run outside of it? Ideal scenario would be to open a google spreadsheet, click on a button, Python script executes and data is filled in said spreadsheet.
Is this possible - Python script to fill a Google spreadsheet?
1
0
1
1
0
3,149
20,693,528
2013-12-19T23:13:00.000
0
0
1
0
0
c++,python,input,keyboard,background-process
0
20,693,595
0
1
0
true
0
0
You need to search for Keyboard Hooks. Most systems provide a away for you to ask to see any events that go by, either all events, or a subset (keyboard/mouse/etc). This can then be used to respond to them. Its used by Macro software such as AutoHotKey, and by Keyloggers, that try to capture peoples passwords and such. If you search for keylogger software, you will probably find some simple examples of use.
1
0
0
0
I want to make a program where when you press a keyboard key it plays the next sound in a list of sounds (preferably using C++ or python), but I want this to work in any program (Microsoft Word etc.) and just be running in the background. I have no idea how to do this or even where to look. Also, if anyone knows a good link for learning how to make a program read midi files, that would be nice too. Thanks a lot.
How do I run a keyboard program in the background?
0
1.2
1
0
0
231
20,695,601
2013-12-20T03:00:00.000
1
1
1
0
0
python,unit-testing,python-imaging-library,pillow
0
23,596,144
0
1
0
false
0
0
Does it have to be exactly 150kb, or just somewhere comfortably over 100kb? One approach would be to create a JPEG at 100% quality, and insert lots of (random) text into all the available EXIF and IPTC headers. Including a large thumbnail image will also push the size up. (And like Bo102010 suggested, you could also use random RGB values to minimise the compression.)
1
5
0
0
I'm trying to work out a method for dynamically generating image files with PIL/Pillow that are a certain file size in order to better exercise certain code paths in my unit tests. For example, I have some image validation code that limits the file size to 100kb. I'd like to generate an image dynamically that is 150kb to ensure that the validation works. It needs to be a valid image and within given dimensions (ie 400x600). Any thoughts on how to add sufficient "complexity" to an image canvas for testing?
Dynamically generate valid image of a certain filesize for testing
0
0.197375
1
0
0
652
20,750,119
2013-12-23T19:42:00.000
1
0
0
0
1
jquery,python,ajax,django
0
20,750,187
0
2
0
false
1
0
This is a frequent mistake when writing JavaScript. You haven't disabled the default actions on click or submit. This means that the JS execute, calling the ajax, but then immediately the normal browser submit is also executed, causing a refresh. voteBehavior should accept an event parameter, and you should call event.preventDefault() at the start of the function.
1
0
0
0
I'm a newbie here, and much of what I have learned about django and python have come from this website. Thank you all for being so helpful! This is my first question post. I've got 2 problems as I try to extend what I've learned from the Django tutorial (1.6) and try to get the Polls app to load via AJAX. I want to use the main mysite app as a home page, and pull in content from other apps in the mysite project using ajax. The tutorial doesn't really cover integrating content from different apps on a single page. I have 2 ajax elements already working on the main mysite page (a "trick or treat" button that retrieves some silly text, and a small dns lookup form/button) but those are part of the mysite app, so all of the logic is handled using the mysite app urlconf, views and templates. There is another div on the page which is for a "Featured App" that will get pulled in, also via ajax. Basically, mysite.views builds a list of apps that have a 'ajaxFeaturedAppView', and then chooses one at random to display in the "Featured App" section on the mysite page. This is my novice attempt at decoupling the mysite app from the other apps as much as possible. Problem 1) The initial poll question and choices and vote button all appear correctly on page load, but the vote button just loads another poll question. It should display poll results. Problem 2) The other ajax elements on the page get triggered when I hit the Vote button, also. I think this is because the Vote button action triggers the document ready() event, which initializes the ajax elements. But the other ajax elements don't do that; they do not trigger the document ready() event. I think that it may be one problem with two symptoms, actually. So, how do I get the vote button to not trigger a document ready event, and will that allow me to see the poll results? Or am I doing something else wrong? EDIT: Okay, there were a few problems with that pieced-together code. Thanks for the help.
AJAX and Django using the polls app from the tutorial: 2 problems
0
0.099668
1
0
0
356
20,777,307
2013-12-25T22:33:00.000
0
0
0
1
1
python,macos,sublimetext,read-eval-print-loop,sublimerepl
0
65,398,436
1
4
0
false
0
0
I would suggest to change the directory to /Library/Frameworks/Python.framework/Versions/Current/bin/python3 This way whenever you update python, SublimeREPL will always get the updated version.
1
5
0
0
My question is the following, I have sublime 2 and sublime repl plugin installed all working fine, the only thing i need is to change the version of python that is running on the sublimerepl built in console. What I mean is, I have python 2.7.5 (which is pre installed with maveriks) running fine in sublime (via sublimerepl), and I have installed via the installer from python.org, python 3.3.3 , that I need to use, I want to run this version of python on the sublimerepl console but I don't know how. I know that there are alternatives to sublime but none of those are so beautiful as sublime is. Can someone help me with this ? I've searched for all over the internet and couldn't find anything helpful. Btw if I use terminal python 3.3.3 is working fine (Terminal>'python3'), I know this is possible beacause a friend of mine got it working and I have installed mine like he did, but mine is not working.
How to run Python 3 in Sublime 2 REPL Mac
0
0
1
0
0
6,952
20,786,478
2013-12-26T14:27:00.000
47
0
1
1
0
python,windows,python-2.7,python-3.x,cmd
0
34,838,251
1
3
0
false
0
0
I also met the case to use both python2 and python3 on my Windows machine. Here's how i resolved it: download python2x and python3x, installed them. add C:\Python35;C:\Python35\Scripts;C:\Python27;C:\Python27\Scripts to environment variable PATH. Go to C:\Python35 to rename python.exe to python3.exe, also to C:\Python27, rename python.exe to python2.exe. restart your command window. type python2 scriptname.py, or python3 scriptname.py in command line to switch the version you like.
1
32
0
0
How can I configure windows command dialog to run different python versions in it? For example when I type python2 it runs python 2.7 and when I type python3 it runs python 3.3? I know how to configure environment variables for one version but two? I mean something like Linux terminal.
How to run different python versions in cmd
0
1
1
0
0
170,536
20,793,740
2013-12-27T02:01:00.000
1
0
1
0
0
python,error-handling
1
28,821,129
0
2
0
false
0
0
Compile errors will be shown when you first try to compile the RPY files. They will be put in "errors.txt" in your project directory. Most errors are not found at compile-time, however, and will only show up once you encounter them at run-time. You can use Lint to check for some common errors (It's called "Check Script (Lint)"), but mostly you'll have to playtest to ensure there are no errors. Errors during playback should pop up a gray screen showing the error and traceback with the option to Ignore, Rollback, or Quit. Is this screen not showing up for you?
2
2
0
0
I'm making a game using Ren'py (based on python) and most errors aren't shown, especially the errors in python code. Is there a possibility to check for possible errors at compile time and how do I get where some errors occur? If there are errors the game normally doesn't run or breaks at the a errors appearance without a message.Is there maybe a file, where they are written in or something like that? Or do I have to debug using logs everywhere?
How do I handle errors in Ren'py
0
0.099668
1
0
0
2,449
20,793,740
2013-12-27T02:01:00.000
0
0
1
0
0
python,error-handling
1
56,918,348
0
2
0
false
0
0
If you're looking for some kind of intellisense like you have for some languages, where as you write the code the IDE shows errors, then it doesn't exist. You have to launch the game so that the code is compiled, just then Ren'py will show you errors. You can see them in the editor or in the errors.txt that Ren'Py creates. To test you python code you can launch the game and type Shift + O to open the console.
2
2
0
0
I'm making a game using Ren'py (based on python) and most errors aren't shown, especially the errors in python code. Is there a possibility to check for possible errors at compile time and how do I get where some errors occur? If there are errors the game normally doesn't run or breaks at the a errors appearance without a message.Is there maybe a file, where they are written in or something like that? Or do I have to debug using logs everywhere?
How do I handle errors in Ren'py
0
0
1
0
0
2,449
20,808,909
2013-12-27T22:52:00.000
0
1
0
1
0
python,apache,mod-wsgi
0
20,809,616
0
1
0
false
0
0
There are two options. Use mod_wsgi daemon mode and run the daemon process as a distinct user. Then lock down all your file permissions appropriately to deny access from that user. The second is that mod_wsgi daemon mode also supports a chroot option. Using a chroot is obviously a lot more complicated to set up however.
1
0
0
0
Lets say I have directory with subdirectories where are projects stored. How to lock Python script inside that subdirectory ? That it can not scan parent directories, read files, import etc. Is it possible with mod_wsgi ? And how to disable any python functions ? Thank
Apache: python directory restriction
1
0
1
0
0
50
20,816,257
2013-12-28T15:38:00.000
0
0
1
1
0
python,macos,automation
0
20,816,671
0
2
0
false
0
0
Set a variable to the future time, and check it in a while() loop
1
0
0
0
I have the following set-up A Python script A Mac OSX Automator application with said script An iCal alert that runs the Automator (and thus the Python script) on a regular schedule All of the above works just fine. But I need to make a change. I need the script to check a web site for a time in the future (that same day) and then come back prior to that time and run itself again. I know how to do the first part (get the time) but I have no clue how to do the second part. How do you get a Python script to (1) run itself at a regular time and then (2) run again at some point in the future? The point in the future will change on a regular basis. Sometimes it would be as early as 10AM, other times it may be 7PM. Any thoughts on this and pseudo-code are welcome. Thanks!
Architecture for a self-running Python script on Mac OSX
0
0
1
0
0
217
20,817,133
2013-12-28T17:07:00.000
1
0
1
0
0
python,django,pycharm
0
63,396,738
0
2
0
false
0
0
Another way is to navigate to the first line using goto line: Ctrl-G and then 1. But this will move the cursor to the first line. A small disadvantage is it is a two step process and adds a navigation step. Moving back to your previous location with CtrlAlt-< will have to be done in two steps if you do an edit.
2
23
0
0
I'm new to PyCharm and haven't been able to figure out what I'm sure is a very simple thing -- what's the key stroke to go to the top of the current file? (Bonus question -- is there a way to scroll to the top of the current file without moving the cursor there also, a la the Home key in Sublime Text 2?)
In PyCharm, how to navigate to the top of the file?
1
0.099668
1
0
0
8,443
20,817,133
2013-12-28T17:07:00.000
19
0
1
0
0
python,django,pycharm
0
20,817,174
0
2
0
true
0
0
You navigate to the top of the file using Ctrl+Home. It moves cursor too. So does navigating via Page Up and Page Down keys. Ctrl+Up and Ctrl+Down move the view without moving cursor but scrolling the long file takes some time. Additionally You can change the keymap (Settings > Keymap). There is 'Scroll to Top' in 'Editor Actions'. You can use Your own key binding for this action, by default (in PyCharm 4 and later) it is not set.
2
23
0
0
I'm new to PyCharm and haven't been able to figure out what I'm sure is a very simple thing -- what's the key stroke to go to the top of the current file? (Bonus question -- is there a way to scroll to the top of the current file without moving the cursor there also, a la the Home key in Sublime Text 2?)
In PyCharm, how to navigate to the top of the file?
1
1.2
1
0
0
8,443
20,832,826
2013-12-30T03:17:00.000
8
0
1
0
0
python,python-3.x,sublimetext
0
33,468,290
0
3
0
false
0
0
Click on tools > build systems > select Python, then Build with using ctr+shif B and select python, and it ll work. Second time you can use the build command, ctr + B since python is now set as default
1
7
0
0
New to Python & Sublime Problem: I type 'print ("Hello world") How do I get it to show me the output (Hello world), is it in a separate window? or... I understand I can use the Python Console built in, but that's a command line, what about when I get to use a ton of code, how do I get the output?
Display Python Output in Sublime text
0
1
1
0
0
29,017
20,847,122
2013-12-30T20:36:00.000
1
0
0
0
0
javascript,python
0
31,151,979
0
4
0
false
1
0
In my opinion, the best option for achieving real time data streaming to a frontend UI is to use a messaging service like pubnub. They have libraries for any language you are going to want to be using. Basically, your user interfaces subscribe to a data channel. Things which create data then publish to that channel, and all subscribers receive the publish very quickly. It is also extremely simple to implement.
1
3
0
0
I am using Flask and I want to show the user how many visits that he has on his website in realtime. Currently, I think a way is to, create an infinite loop which has some delay after every iteration and which makes an ajax request getting the current number of visits. I have also heard about node.js however I think that running another process might make the computer that its running on slower (i'm assuming) ? How can I achieve the realtime updates on my site? Is there a way to do this with Flask? Thank you in advance!
How to achieve realtime updates on my website (with Flask)?
0
0.049958
1
0
0
5,285
20,847,649
2013-12-30T21:11:00.000
0
0
0
1
1
python,aptana,pydev
0
21,073,033
1
3
0
false
1
0
Aptana 3.5.0 and PyDev 3.0 does not work under Mac OS X 10.9 Mavericks yet. PyDev reports builtin symbols such as None could not be recognized. I rolled back to 3.4.2 as well.
2
0
0
0
Aptana Studio is my primary Python IDE and I have been using it for years with much joy and success! Recently, when I start Aptana Studio it fails to recognize any PyDev projects that I have previously created. I noticed that this was happening after installing a recent update of the IDE. I tried uninstalling Aptana and resinstalling the latest version from the website. Nada...I updated Java thinking there might be a misalignment between Java versions or something like that. Nada...The latest version of Eclipse works fine and Aptana seems to be functioning correctly for everything except for PyDev (Python). I am running a current version of Windows 8. Does anyone know how to fix this or maybe trouble shoot the problem? PyDev worked perfectly in Aptana Studio until I installed the update. Has anyone come across this and know how to fix it?
PyDev won't start in Aptana Studio3
0
0
1
0
0
666
20,847,649
2013-12-30T21:11:00.000
0
0
0
1
1
python,aptana,pydev
0
20,851,621
1
3
0
false
1
0
I went back to the Aptana website and this time around it gave me Aptana Studio 3, build: 3.4.2.201308081805 which works fine. 3.5.0 does still not appear to work for Python development at the moment.
2
0
0
0
Aptana Studio is my primary Python IDE and I have been using it for years with much joy and success! Recently, when I start Aptana Studio it fails to recognize any PyDev projects that I have previously created. I noticed that this was happening after installing a recent update of the IDE. I tried uninstalling Aptana and resinstalling the latest version from the website. Nada...I updated Java thinking there might be a misalignment between Java versions or something like that. Nada...The latest version of Eclipse works fine and Aptana seems to be functioning correctly for everything except for PyDev (Python). I am running a current version of Windows 8. Does anyone know how to fix this or maybe trouble shoot the problem? PyDev worked perfectly in Aptana Studio until I installed the update. Has anyone come across this and know how to fix it?
PyDev won't start in Aptana Studio3
0
0
1
0
0
666
20,852,789
2013-12-31T06:18:00.000
4
0
1
0
0
python
0
20,852,864
0
3
0
false
0
0
A dictionary of key value pairs: __builtins__.__dict__ Only the objects: __builtins__.__dict__.values() These will give you a list of a dictionary you can iterate over to your hearts content! EDIT: Not recommended, see below comment and that users answer
1
1
0
0
how can i get a list of all built-in objects in python recursively? what i'm exactly searching for is a function like dir() which returns a list of objects instead of strings. also, why does "dir(__builtins__.print)" fail in python's interactive mode with a syntax error? thanks for your answers!
How can i get a list of all built-in objects in python recursively?
0
0.26052
1
0
0
23,981
20,854,222
2013-12-31T08:24:00.000
2
0
0
0
0
python,google-nativeclient
0
20,912,809
0
1
0
true
1
0
The interpreter is currently the only python example in naclports. However, it should be possible to link libpython into any nacl binary, and use it just as you would embed python in any other C/C++ application. A couple of caveats: you must initialize nacl_io before making any python calls, and as you should not make python calls on the main (PPAPI) thread. In terms of interacting with the HTML page, as with all NaCl applications this must be done by sending messages back and forth between native and javascript code using PostMessage(). There is no way to directly access the HTML or JavaScript from native code.
1
1
0
0
There is a Python interpreter in naclports (to run as Google Chrome Native Client App). Are there any examples for bundling the interpreter with a custom Python application and how to integrate this application with a HTML page?
Practical use of Python as Chrome Native Client
0
1.2
1
0
1
779
20,856,854
2013-12-31T11:44:00.000
0
1
0
0
1
python,web2py
1
54,032,848
0
2
0
false
1
0
I was getting a very similar error ("name 'auth' is not defined"). Had to add from django.contrib import auth at the top of views.py and it worked.
1
1
0
0
I have a web2py application where I have written various modules which hold business logic and database related stuff. In one of the files I am trying to access auth.settings.table_user_name but it doesn't work and throws and error as global name 'auth' is not defined. If I write the same line in controller, it works. But I want it to be accessed in module file. Please suggest how do I do that.
auth is not available in module
0
0
1
0
0
2,882
20,878,709
2014-01-02T08:01:00.000
2
0
0
0
0
python,django,django-models
0
21,235,393
0
1
0
false
1
0
The original confusion is that Django tries to connect to its databases on startup. This is actually not true. Django does not connect to database, until some app tries to access the database. Since my web application uses auth and site apps, it looks like it tries to connect on startup. But its not tied to startup, its tied to the fact that those app access the database "early". If one defines second database backend (non-default), then Django will not try connecting to it unless application tries to query it. So the solution was very trivial - originally I had one database that hosted both auth/site data and also "real" data that I've exposed to users. I wanted to make "real" database connection to be volatile. So I've defined separate psql backend for it and switched default backend to sqlite. Now when trying to access "real" database through Query, I can easily wrap it with try/except and handle "Sorry, try again later" over to the user.
1
1
0
0
I have a Django app that has several database backends - all connected to different instances of Postgresql database. One of them is not guaranteed to be always online. It even can be offline when application starts up. Can I somehow configure Django to use lazy connections? I would like to: Try querying return "sorry, try again later" if database is offline or return the results if database is online Is this possible?
Lazy psql connection with Django
1
0.379949
1
1
0
380
20,897,140
2014-01-03T05:28:00.000
1
0
0
0
0
python,image,numpy,fill,polygons
0
20,914,427
0
1
0
true
0
0
In this case the point to achieve speed is more the used algorithms than the language of choice. Drawing and filling poligons rasterized over a grid of pixel falls into the domain of image processing algorithms and for sure AggDraw is using algorithms from that field. The idea is that if you evaluate for each points a function that considers the vectorial nature of the polygon you need to do a number of operations that is at least O(2*p*A) where: A = image area p = average number of points in the perimeter of the polygons. Conversely if you use image processing algorithms for each point you can consider to have a fixed and low number of operations. For example if you consider the FloodFill algorithm it is O(A) and I can say it is less than 30*A (about 30 operations per pixel). So basically since the GADM polygons has many vertex is better to eliminate the vectorial nature of the problem as soon as possible and go with something like this: construct the pixel map of the boundary find one internal pixel use the Floodfill algorithm that will work without any need to know about polygons as vectorial entities The same algorithms can for sure be implemented in Numpy but before going for a Numpy graphical lib I would suggest to do the following: measure the time spent in your code for the various steps: Numpy array to AggDraw lists/sequences conversion time taken by AggDraw try to decimate the vertex of the polygons removing the ones that stay in the same pixel based on the current Zoom level and see if an how the times will be reduced
1
3
1
0
Here goes a difficult one for the expert Numpyer! Does someone know or can come up with a way to use pure Numpy arrays and functions to draw as well as fill colored polygons on top of a numpy array grid? This I think would take two steps: The ability to fill the grid array with color values so that the polygon filling could be written in one color, and the outline in another one. What would be ideal and fastest for such a system, eg tuples of rgb values, color name strings, etc? The ability to draw and fill the inside of a polygon based on an array of its pixel coordinates. Drawing the outline of it I think should be pretty easy by just using the coordinates as indexes to the grid array and setting them to the outline color values. More difficult would be to fill the polygon. One way would be to iterate through all pixel cell coordinates (or better yet only for the neighboring cells of each polygon coordinate point) and test if its coordinates are within the polygon pixel coordinates. I know there are some simple inside-outside/biggerthan-smallerthan algorithms to test for point in poly using regular Python, but for my purpose this would be too slow and I am wondering if someone has the numpy skills to set up such an advanced linked code using only the speed of the numpy builtin functions to return True if a numpy pixel coordinate is inside a polygon. Lastly, if someone would know how to draw a line between two pixel/grid/array coordinates by filling in all the cells in between two pixels with a True or color value? I know this is a tall order, but I was just curious to see if anyone would know. If so, then this could make for a pretty powerful and fast Numpy-based drawing library. In the end I would like to save the grid array as an image which is easy by passing it to PIL. I am aware that PIL and Aggdraw can do the polygon drawings and that this has been suggested in many similar posts, but they are not very effective when receiving a numpy array of xy polygon/line coordinates. The assumption here is that my polygon coordinates are already in a numpy array format and I want to avoid the overhead of having to copy them into lists for every drawing (when we're talking about thousands of polygons frequently). So the difference in this post is about how to fill a polygon using pure Numpy.
How to draw and fill a polygon on a grid array using pure Numpy functions?
1
1.2
1
0
0
2,144
20,900,530
2014-01-03T09:36:00.000
1
0
0
0
0
javascript,html,python-2.7,pyjamas
0
20,901,453
0
1
0
false
1
0
There are more than just security problems. It's just not possible. You can't use the Python socket library inside the client browser. You can convert Python code to JS (probably badly) but you can't use a C based library that is probably not present on the client. You can access the browser only. You cannot reliably get the hostname of the client PC. Maybe ask another question talking about what you are trying to achieve and someone might be able to help
1
0
0
0
I want to execute my python code on the side even though there might be security problem How can I write with importing modules and all? I have tried using of pyjs to convert the below code to JS import socket print socket.gethostbyname_ex(socket.gethostname())[2][0] but I am not find how to do the same. Please help me how to how can convert this to JS and how to write other the python scripts and how to import modules in HTML.
How to Write Python Script in html
0
0.197375
1
0
1
152
20,911,147
2014-01-03T19:20:00.000
1
0
0
0
0
python,numpy
0
20,911,192
0
5
0
false
0
0
When people need a random seed that can be recorded, people usually use the system time as a random seed. This means your program will act differently each time it is run, but can be saved and captured. Why don't you try that out? If you don't want to do that for some reason, use the null version, numpy.random.seed(seed=None), then get a random number from it, then set the seed to that new random number.
1
11
1
0
I would like to choose a random seed for numpy.random and save it to a variable. I can set the seed using numpy.random.seed(seed=None) but how do you get numpy to choose a random seed and tell you what it is? Number seems to use /dev/urandom on linux by default.
Choose random seed and save it
0
0.039979
1
0
0
6,170
20,916,549
2014-01-04T03:40:00.000
0
0
1
0
0
python
0
20,916,569
0
2
0
false
0
0
I don't want to have to maintain a list It's what you are meant to do; and you would have to use loops anyway. You're effectively asking the language to create a list for you automatically. Well, why would it? Contrary to what you might expect, you almost always will not need or want a list of every single instance of a class ever created. In fact, it's entirely possible that you don't even really want that for your current program (whether you yet realize it or not). There are all kinds of possible reasons, in practice, why you might want to create instances that are not subject to the "usual" handling.
1
2
0
0
I have a class called Mobilesuits and each instance of that class has an attribute called coordinates, which consists of its grid coordinates, which are in a list(x,y,z). I am trying to make a radar method which would detect how close a given vehicle is to other vehicles, but can't find a way to reference every objects coordinates simultaneously. Is there an easy way to do this in Python? I don't want to have to maintain a list of all vehicles and every time I want to perform a global change go through the whole list with a for loop, but that is the only way I can think of.
How do I reference all class instances at the same time?
0
0
1
0
0
73
20,931,426
2014-01-05T08:04:00.000
1
0
0
0
0
python,selenium,web-scraping,cloudflare
0
23,142,928
0
1
0
false
1
0
See, what scrapeshield does is checking if you are using a real browser, it's essentially checking your browser for certain bugs in them. Let's say that Chrome can't process an IFrame if there is a 303 error in the line at the same time, certain web browser react differently to different tests, so webdriver must not react to these causing the system to say "We got an intruder, change the page!". I might be correct, not 100% sure though... More Info on source: I found most of this information on a Defcon talk about web sniffers and preventing them from getting the proper vulnerability information on the server, he made a web browser identifier in PHP too.
1
7
0
0
I'm working on a webscraping project, and I am running into problems with cloudflare scrapeshield. Does anyone know how to get around it? I'm using selenium webdriver, which is getting redirected to some lightspeed page by scrapeshield. Built with python on top of firefox. Browsing normally does not cause it to redirect. Is there something that webdriver does differently from a regular browser?
Bypassing Cloudflare Scrapeshield
1
0.197375
1
0
1
4,617
20,933,214
2014-01-05T11:51:00.000
1
0
0
0
0
python,django,rest,tastypie
0
21,005,266
0
2
0
false
1
0
This sounds like something completely outside of TastyPie's wheelhouse. Why not have a single view somewhere decorated with @require_GET, if you want to control headers, and return an HttpResponse object with the desired payload as application/json? The fact that your object is a singleton and all other RESTful interactions with it are prohibited suggests that a REST library is the wrong tool for this job.
1
8
0
0
I'm using tastypie and I want to create a Resource for a "singleton" non-model object. For the purposes of this question, let's assume what I want the URL to represent is some system settings that exist in an ini file. What this means is that...: The fields I return for this URL will be custom created for this Resource - there is no model that contains this information. I want a single URL that will return the data, e.g. a GET request on /api/v1/settings. The returned data should return in a format that is similar to a details URL - i.e., it should not have meta and objects parts. It should just contain the fields from the settings. It should not be possible to GET a list of such object nor is it possible to perform POST, DELETE or PUT (this part I know how to do, but I'm adding this here for completeness). Optional: it should play well with tastypie-swagger for API exploration purposes. I got this to work, but I think my method is kind of ass-backwards, so I want to know what is the common wisdom here. What I tried so far is to override dehydrate and do all the work there. This requires me to override obj_get but leave it empty (which is kind of ugly) and also to remove the need for id in the details url by overriding override_urls. Is there a better way of doing this?
Creating a tastypie resource for a "singleton" non-model object
0
0.099668
1
0
0
1,156
20,954,090
2014-01-06T16:07:00.000
0
0
0
0
0
python,django,url,filepath,file-structure
0
20,954,419
0
2
0
false
1
0
I would suggest looking into forms on the Django documentation site. When the user submits the form the appropriate file structure information will be passed to your view code. The view code can then pass the new file structure information to your template. The template will create the forms and the process will start over again.
1
0
0
0
I am attempting to create a django based website. The goal of one part of the site is to show the contents of a database in reference to its file structure. I would like to keep the URL the same while traveling deeper into the file structure, as opposed to developing another view for each level of the file structure a person goes into. The simplest way I can think to achieve this is to pass the current directory path in the request variable but I am not sure how to do this or if it is possible since it would have to be linked in the html file, and not the view file that is written in python. If you are able to at very least point me in the right direction it would be greatly appreciated!
Keep URL while surfing data Structure in Django web app
1
0
1
0
0
163
20,984,266
2014-01-07T23:39:00.000
2
0
0
0
0
python,python-2.7,csv,random,pandas
0
20,984,538
0
1
0
false
0
0
There are many ways to implement this, but the abstract algorithm should be something like this. First, to create a new CSV that meets your second critera about each state being drawn with equal probability, draw each row as follows. 1) From the set of states, draw a state (each state is drawn with probability 1 / # of states). Let that state be s. 2) From the large CSV, draw a row from the set of rows where STATE = s. As you draw rows, keep a record of the number of rows drawn from a given state/city pair. You could do this with a dictionary. Then, each time you draw a successive row, if there are any state/city pairs equal to the cap set by the user, exclude those state/city pairs from your conditional draw in step 2 above. This will satisfy your first requirement. Does that make sense? If you get started with a bit of code that attempts to implement this, I'll happily tidy it up for you if it has any problems. If you wanted to do the "somewhat trickier" algorithm in which the probability of selecting a city decreases with each selection, you could do that without much trouble. Basically, condition on the cities within state s after you draw s, then weight according to the number of times each city in that state has been drawn (you have this information because you've been storing it to implement the first requirement). You'll have to come up with the form of the weighting function, as it isn't implied by your description. Again, if you try to code this up, I'm happy to take a look at any code you post and make suggestions.
1
0
1
0
I have a (large) directory CSV with columns [0:3] = Phone Number, Name, City, State. I created a random sample of 20,000 entries, but it was, of course, weighted drastically to more populated states and cities. How would I write a python code (using CSV or Pandas - I don't have linecache available) that would equally prioritize/weight each unique city and each state (individually, not as a pair), and also limit each unique city to 3 picks? TRICKIER idea: How would I write a python code such that for each random line that gets picked, it checks whether that city has been picked before. If that city has been picked before, it ignores it and picks a random line again, reducing the number of considered previous picks for that city by one. So, say that it randomly picks San Antonio, which has been picked twice before. The script ignores this pick, places it back into the list, reduces the number of currently considered previous San Antonio picks, then randomly chooses a line again. IF it picks a line from San Antonio again, then it repeats the previous process, now reducing considered San Antonio picks to 0. So it would have to pick San Antonio three times in a row to add another line from San Antonio. For future picks, it would have to pick San Antonio four times in a row, plus one for each additional pick. I don't know how well the second option would work to "scatter" my random picks - it's just an idea, and it looks like a fun way to learn more pythonese. Any other ideas along the same line of thought would be greatly appreciated. Insights into statistical sampling and sample scattering would also be welcome.
Dispersing Random Sampling in CSV through Python
0
0.379949
1
0
0
114