Q_CreationDate
stringlengths
23
23
Title
stringlengths
11
149
Question
stringlengths
25
6.53k
Answer
stringlengths
15
5.1k
Score
float64
-1
1.2
Is_accepted
bool
2 classes
N_answers
int64
1
17
Q_Id
int64
0
6.76k
2012-06-07 11:00:00.763
Django: how to properly handle a database connection error
I have a desktop application that send POST requests to a server where a django app store the results. DB server and web server are not on the same machine and it happens that sometimes the connectivity is lost for a very short time but results in a connection error on some requests: OperationalError: (2003, "Can't co...
You could use a middleware with a process_view method and a try / except wrapping your call. Or you could decorate your views and wrap the call there. Or you could use class based views with a base class that has a method decorator on its dispatch method, or an overriden.dispatch. Really, you have plenty of solutions....
0.201295
false
1
1,906
2012-06-08 22:21:34.060
Ruby on Rails frontend and server side processing in Python or Java.. HOW, What, Huh?
I am a data scientist and database veteran but a total rookie in web development and have just finished developing my first Ruby On Rails app. This app accepts data from users submitting data to my frontend webpage and returns stats on the data submitted. Some users have been submitting way too much data - its getting ...
Are you sure your database is well maintained and efficient (good indexes, normalised, clean etc) Or can you not make use of messaging queues, so you keep your rails crud app, then the jobs are just added to a queue. Python scripts on the backend (or different machine) read from the queue, process then insert back into...
0
false
1
1,907
2012-06-09 00:34:42.817
Python, using a comparison function for finding the best object
I have a function that takes as parameters 2 objects: a and b The function checks (with a very long algorithm) which one of these objects is better. If a is better it returns -1, if b is better it returns 1, if they tied it returns 0 My problem is: I have 21 of these objects in a list. I need to find out, using the fun...
The most straightforward way: Create an object of each one, with your comparison function as __cmp__ (python 2.x) or define __lt__ and __eq__ (python 3.x). Stash each one in a list named list_. Find the least valued one using min(list_). An optimization that might help, if practical: If you can come up with a way of ...
0.201295
false
1
1,908
2012-06-09 11:39:06.600
How can I get the exact memory address on HDD of an file?
I'm going to make a kind of remover that erase files never recoverable. I don't know the algorithm but I think it is possible to get exact file memory address and write something like 'null' at there. So I'm searching at os module and others, but don't know how to do that...Is there a function or the otherway? Or what ...
Unless you entirely control the system, I think you'd be better off abandoning this particular pursuit. Modern filesystems or mediums (e.g. SSD wear-leveling) can result in data being retained physically on-disk even if you overwrite them in-place. Best practice in my book is to fill the disk with random data, then ex...
1.2
true
1
1,909
2012-06-10 22:25:42.943
Reordering in IconView (PyGtk)
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True). My question is what is the best way to retrieve the new order? That is, how should I access a property of each of the elements in the new order? An iterator of sorts? I am using gtk.ListStore to store the dat...
So, I understand now: it turns out that when items are reordered in IconView, gtk.ListStore.reorder or something similar is called. What that means is that all I needed to do was to use gtk.ListStore.get_iter() or gtk.ListStore.get_iter_first() and all the problems are solved. How trivial! All I needed to do was eat ...
1.2
true
1
1,910
2012-06-12 10:04:36.633
Python timeit: results cached instead of calculated?
I am testing several different algorithms (for solving 16x16 sudokus) against each other, measuring their performance using the timeit module. However, it appears that only the first of the timeit.repeat() iterations is actually calculated, because the other iterations are gotten much faster. Testing a single algori...
I think the memory allocation is the problem. the python interpreter itself holds a memory pool, which starts with no (or little?) memory pooling. after the first run of your program, much memory is allocated (from the system) and free (to the pool), and then the following runs get memory from the pool, which is much f...
0.673066
false
1
1,911
2012-06-12 15:14:43.370
A single factory for multiple protocols?
I am trying to implement a network protocol that listens on 2 separate TCP ports. One is for control messages and one is for data messages. I understand that I need two separate protocol classes since there are two ports involved. I would like to have one factory that creates both of these protocols since there is stat...
Your factory's buildProtocol can return anything you want it to return. That's up to you. However, you might find that things are a lot simpler if you just use two different factories. That does not preclude sharing state. Just have them share a bunch of attributes, or collect all your state together onto a single n...
1.2
true
1
1,912
2012-06-13 11:28:11.367
python: how to have a dictionary which can be accessed from all the app
I am new to Python and have been studying its fundementals for 3 months now, learning types, functions and algorithms. Now I started practiciging web app development with GAE framework. Goal: have a very large dictionary, which can be accessed from all .py files throughout the web app without having it stored more than...
This is impossible (without an external service). DBs are made for this to store data longer than one request. What you could do is to safe the dict "in" the users session, but I don't recommend that. Unless you have millions of entries every DB is fast enough even sqlite.
-0.265586
false
1
1,913
2012-06-13 11:31:50.497
Maintaining data integrity in mysql when different applications are accessing it
Okay., We have Rails webapp which stores data in a mysql data base. The table design was not read efficient. So we resorted to creating a separate set of read only tables in mysql and made all our internal API calls use that tables for read. We used callbacks to keep the data in sync between both the set of tables. Now...
Yes, refactor the code to put a data web service in front of the database and let the Ruby and Python apps talk to the service. Let it maintain all integrity and business rules. "Don't Repeat Yourself" - it's a good rule.
1.2
true
1
1,914
2012-06-13 12:56:13.887
How to create a trie in Python
I'm interested in tries and DAWGs (direct acyclic word graph) and I've been reading a lot about them but I don't understand what should the output trie or DAWG file look like. Should a trie be an object of nested dictionaries? Where each letter is divided in to letters and so on? Would a lookup performed on such a dic...
There's no "should"; it's up to you. Various implementations will have different performance characteristics, take various amounts of time to implement, understand, and get right. This is typical for software development as a whole, in my opinion. I would probably first try having a global list of all trie nodes so far...
0.363534
false
1
1,915
2012-06-13 21:25:21.017
Python to list HTTP-files and directories
How can I list files and folders if I only have an IP-address? With urllib and others, I am only able to display the content of the index.html file. But what if I want to see which files are in the root as well? I am looking for an example that shows how to implement username and password if needed. (Most of the time i...
HTTP does not work with "files" and "directories". Pick a different protocol.
0.3154
false
2
1,916
2012-06-13 21:25:21.017
Python to list HTTP-files and directories
How can I list files and folders if I only have an IP-address? With urllib and others, I am only able to display the content of the index.html file. But what if I want to see which files are in the root as well? I am looking for an example that shows how to implement username and password if needed. (Most of the time i...
You cannot get the directory listing directly via HTTP, as another answer says. It's the HTTP server that "decides" what to give you. Some will give you an HTML page displaying links to all the files inside a "directory", some will give you some page (index.html), and some will not even interpret the "directory" as one...
0.989027
false
2
1,916
2012-06-14 05:49:29.190
wxPython : Adjusting the panels and sizers for different screen resolutions
So, here I'm happy that I wrote the whole code for a awesome looking GUI using wxPython in a day but it evaporated when I found that the panels are getting out of the way leaving a lot of empty space on the sides or getting congested (you know how!) on a different screen resolution. What I want to ask is that what all...
Sizers automatically adjust your application widgets for screen resolution, resize, etc. If they aren't doing this automatically, then there's probably something buggy in your code. Since I don't have your code to look at, try going over the wxPython tutorials on sizers very carefully. I found the book wxPython In Acti...
0.673066
false
1
1,917
2012-06-14 13:15:59.820
SQLAlchemy(Postgresql) - Race Conditions
We are writing an inventory system and I have some questions about sqlalchemy (postgresql) and transactions/sessions. This is a web app using TG2, not sure this matters but to much info is never a bad. How can make sure that when changing inventory qty's that i don't run into race conditions. If i understand it corre...
If two transactions try to set the same value at the same time one of them will fail. The one that loses will need error handling. For your particular example you will want to query for the number of parts and update the number of parts in the same transaction. There is no race condition on sequence numbers. Save a re...
1.2
true
1
1,918
2012-06-14 13:34:46.200
Search unreliable author names
We have scanned thousands of old documents and entered key data into a database. One of the fields is author name. We need to search for documents by a given author but the exact name might have been entered incorrectly as on many documents the data is handwritten. I thought of searching for only the first few letters ...
I think you can use mongodb where you can set list field with all possible names of author. For example you have handwriten name "black" and you cant recognize what letter in name for example "c" or "e" and you can set origin name as "black" and add to list of possible names "blaek"
0
false
1
1,919
2012-06-14 22:22:23.963
MVVM pattern with PySide
I've been trying to find a way to implement MVVM with PySide but haven't been able to. I think that there should be a way to create Views from ViewModels with QItemEditorFactory, and to do data binding I think I can use QDataWidgetMapper. Do you have any ideas on how MVVM may be implemented with Qt and PySide? Even if ...
An obvious answer for me is that MVVM is suitable for WPF and some other techs that welcome this pattern, and so you have to find out whether it's possible to apply this pattern on other technologies. Please, read on MVVM in wiki.
-0.265586
false
2
1,920
2012-06-14 22:22:23.963
MVVM pattern with PySide
I've been trying to find a way to implement MVVM with PySide but haven't been able to. I think that there should be a way to create Views from ViewModels with QItemEditorFactory, and to do data binding I think I can use QDataWidgetMapper. Do you have any ideas on how MVVM may be implemented with Qt and PySide? Even if ...
I don't know how far do you want to take MVVM, but at a basic level it comes with Qt, and I've been using it for a long time. You have a business-specific model, say tied to a database. Then you create view-specific viewmodel as a proxy model. You can stack a few layers of those, depending on what you need. Then you sh...
0
false
2
1,920
2012-06-15 08:03:51.487
Python: Does after() in Tkinter have a multi-threading approach?
I'm writing a physics simulating program, and found after() useful. I once would like to create a thread for physics calculation and simulation. But when I finally noticed that function, I used it instead. So, I'm curious about how Tkinter implements that function. Is it multi-threading?
It is not multithreaded. Tkinter works by pulling objects off of a queue and processing them. Usually what is on this queue are events generated by the user (mouse movements, button clicks, etc). This queue can contain other things, such as job created with after. So, to Tkinter, something submitted with after is just...
1.2
true
1
1,921
2012-06-15 15:18:06.597
Documentation when not using getters and setters
In Java I use getters/setters when I have simple models/pojos. I find that the code becomes self-documenting when you do it this way. Calling getName() will return a name, I don't need to care how it's mapped to some database and so on. Problems rise when using languages where getters and setters start feeling clunky, ...
In my opinion, there shouldn't be any undocumented attributes in a class. PHP and other languages allow you to just stick attributes on a class from anywhere, whether they've been defined in the class or not. I think that's bad practice for the reasons you describe and more: It's hard to read. It makes it harder for ...
1.2
true
1
1,922
2012-06-18 10:45:01.240
how to install python-rest-client lib in linux
I need to use python-rest-client package into my project. I tried several times for installing python-rest-client into my linux python, it never worked. But it works well in Windows python. Would anybody tell me how to install python-rest-client in linux python.
avasal, you were right. I did it by pip install python-rest-client
1.2
true
1
1,923
2012-06-18 13:27:32.410
Support Vector Regression with High Dimensional Output using python's libsvm
I would like to ask if anyone has an idea or example of how to do support vector regression in python with high dimensional output( more than one) using a python binding of libsvm? I checked the examples and they are all assuming the output to be one dimensional.
libsvm might not be the best tool for this task. The problem you describe is called multivariate regression, and usually for regression problems, SVM's are not necessarily the best choice. You could try something like group lasso (http://www.di.ens.fr/~fbach/grouplasso/index.htm - matlab) or sparse group lasso (http://...
0.673066
false
1
1,924
2012-06-18 21:07:09.300
IDLE not integrated in desktop
Just installed Python 2.7.3 on a Windows7 machine. How do I get .py files to be associated with python (they are with notepad ATM) and how do I get the context menu shortcut for "edit in IDLE"? Somehow I didn't get that on this particular computer.
try making a .py file and then try to open it, and a window should appear asking you what to open it with, and then select idle in your program files.
1.2
true
1
1,925
2012-06-19 05:33:27.033
How do you run the Tornado web server locally?
Is it possible to run Tornado such that it listens to a local port (e.g. localhost:8000). I can't seem to find any documentation explaining how to do this.
Once you've defined an application (like in the other answers) in a file (for example server.py), you simply save and run that file. python server.py
0.101688
false
2
1,926
2012-06-19 05:33:27.033
How do you run the Tornado web server locally?
Is it possible to run Tornado such that it listens to a local port (e.g. localhost:8000). I can't seem to find any documentation explaining how to do this.
If you want to daemonize tornado - use supervisord. If you want to access tornado on address like http://mylocal.dev/ - you should look at nginx and use it like reverse proxy. And on specific port it can be binded like in Lafada's answer.
0
false
2
1,926
2012-06-19 06:00:48.470
How to read other files in hadoop jobs?
I need to read in a dictionary file to filter content specified in the hdfs_input, and I have uploaded it to the cluster using the put command, but I don't know how to access it in my program. I tried to access it using path on the cluster like normal files, but it gives the error information: IOError: [Errno 2] No suc...
Problem solved by adding the file needed with the -file option or file= option in conf file.
1.2
true
1
1,927
2012-06-19 09:26:57.937
how to write python wrapper of a java library
How can we write a python (with CPython) binding to a Java library so that the developers that want to use this java library can use it by writing only python code, not worrying about any Java code?
I've used JPype in a similar instance with decent results. The main task would be to write wrappers to translate your java api into a more pythonic api, since raw JPype usage is hardly any prettier than just writing java code.
0.386912
false
1
1,928
2012-06-19 11:33:08.267
how to save a boolean numpy array to textfile in python?
The following saves floating values of a matrix into textfiles numpy.savetxt('bool',mat,fmt='%f',delimiter=',') How to save a boolean matrix ? what is the fmt for saving boolean matrix ?
Thats correct, bools are integers, so you can always go between the two. import numpy as np arr = np.array([True, True, False, False]) np.savetxt("test.txt", arr, fmt="%5i") That gives a file with 1 1 0 0
0.995055
false
1
1,929
2012-06-20 13:15:23.843
Custom QGridLayout items selection behaviour
How can I change behavior of how items are selected in QGridLayout by cursor keys? I want to move selection horizontally by left/right cursor keys and vertically by up/down keys. Who is responsible for it? Layout, items container or tab order?
You can reimplement keyPressEvent() method for the main widget to catch the pressed keys. Then you can access the desired widget in your layout by calling QGridLayout::itemAtPosition (int row, int column) and then set focus to it.
1.2
true
1
1,930
2012-06-20 23:59:54.870
Optimal format for simple data storage in python
As a relatively new programmer, I have several times encountered situations where it would be beneficial for me to read and assemble program data from an external source rather than have it written in the code. This is mostly the case when there are a large number of objects of the same type. In such scenarios, object ...
If you want editability, YAML is the best option of the ones you've named, because it doesn't have <> or {} required delimiters.
0.050976
false
3
1,931
2012-06-20 23:59:54.870
Optimal format for simple data storage in python
As a relatively new programmer, I have several times encountered situations where it would be beneficial for me to read and assemble program data from an external source rather than have it written in the code. This is mostly the case when there are a large number of objects of the same type. In such scenarios, object ...
I would be tempted to research a little into some GUI that could output graphviz (DOT format) with annotations, so you could create the rooms and links between them (a sort of graph). Then later, you might want another format to support heftier info. But should make it easy to create maps, links between rooms (containi...
0
false
3
1,931
2012-06-20 23:59:54.870
Optimal format for simple data storage in python
As a relatively new programmer, I have several times encountered situations where it would be beneficial for me to read and assemble program data from an external source rather than have it written in the code. This is mostly the case when there are a large number of objects of the same type. In such scenarios, object ...
Though there are good answers here already, I would simply recommend JSON for your purposes for the sole reason that since you're a new programmer it will be the most straightforward to read and translate as it has the most direct mapping to native Python data types (lists [] and dictionaries {}). Readability goes a l...
0.249709
false
3
1,931
2012-06-21 01:32:33.530
top user authentication method for google app engine
Having ease of implementation a strong factor but security also an issue what would the best user authentication method for google app engine be? My goal is to have a small very specific social network. I know how to make my own but making it hack-proof is a little out of my league right now. I have looked at OpenID...
Your choices are Google's own authentication, OpenID, some third party solution or roll your own. Unless you really know what you are doing, do not choose option 4! Authentication is very involved, and if you make a single mistake or omission you're opening yourself up to a lot of pain. Option 3 is not great because yo...
1.2
true
1
1,932
2012-06-21 08:50:26.320
Find perpendicular to given vector (Velocity) in 3D
I have a object A move with Velocity (v1, v2, v3) in 3D space. Object position is (px,py,pz) Now i want to add certain particles around object A (in radius dis) on plane which perpendicular to its Velocity direction. I find something call "cross product" but seen that no use in this case. Anyone can help? I'm new to py...
The plane perpendicular to a vector ⟨A, B, C⟩ has the general equation Ax + By + Cz + K = 0.
0.201295
false
1
1,933
2012-06-21 16:15:54.423
Does Python have an immutable list?
Does python have immutable lists? Suppose I wish to have the functionality of an ordered collection of elements, but which I want to guarantee will not change, how can this be implemented? Lists are ordered but they can be mutated.
Instead of tuple, you can use frozenset. frozenset creates an immutable set. you can use list as member of frozenset and access every element of list inside frozenset using single for loop.
-0.058243
false
1
1,934
2012-06-21 16:22:15.197
Throw blank even-numbered/left pages
I am trying to typeset a large document using ReportLab and Python 2.7. It has a number of sections (about 6 in a 1,000 page document) and I would like each to start on odd-numbered/right-hand page. I have no idea though whether the preceding page will be odd or even and so need the ability to optionally throw an addi...
If you can keep track of page numbers, then just add a PageBreak or canvas.showPage() command at the appropriate times.
0
false
1
1,935
2012-06-23 01:02:54.777
Importing unfinished modules
I'm building a personal module of functions, generic functions for my scientific work. It's not finished so I would like to keep it in it's development folder for the time being without installing it like you install every other modules with pip, etc. Now, I also need to work on other non-related projects but still nee...
Put the directory containing your module (let's call it functions.py) into the PYTHONPATH environment variable. Then you'll be able to use import functions to get your functions. Pip also seems to have support for this: pip install -e src/mycheckout for exxample, but I don't quite understand the ramifications of that...
1.2
true
1
1,936
2012-06-23 01:15:42.310
How to tell if you have multiple Django's installed
In the process of trying to install django, I had a series of failures. I followed many different tutorials online and ended up trying to install it several times. I think I may have installed it twice (which the website said was not a good thing), so how do I tell if I actually have multiple versions installed? I have...
open terminal and type python then type import django then type django and it will tell you the path to the django you are importing. Goto that folder [it should look something like this: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/] and look for more than one instance of django(if the...
1.2
true
2
1,937
2012-06-23 01:15:42.310
How to tell if you have multiple Django's installed
In the process of trying to install django, I had a series of failures. I followed many different tutorials online and ended up trying to install it several times. I think I may have installed it twice (which the website said was not a good thing), so how do I tell if I actually have multiple versions installed? I have...
Check out virtualenv and virtualenvwrapper
0.591696
false
2
1,937
2012-06-23 15:46:23.330
How do I tell a Python script to use a particular version
How do I, in the main.py module (presumably), tell Python which interpreter to use? What I mean is: if I want a particular script to use version 3 of Python to interpret the entire program, how do I do that? Bonus: How would this affect a virtualenv? Am I right in thinking that if I create a virtualenv for my program a...
You can't do this within the Python program, because the shell decides which version to use if you a shebang line. If you aren't using a shell with a shebang line and just type python myprogram.py it uses the default version unless you decide specifically which Python version when you type pythonXXX myprogram.py which...
0
false
3
1,938
2012-06-23 15:46:23.330
How do I tell a Python script to use a particular version
How do I, in the main.py module (presumably), tell Python which interpreter to use? What I mean is: if I want a particular script to use version 3 of Python to interpret the entire program, how do I do that? Bonus: How would this affect a virtualenv? Am I right in thinking that if I create a virtualenv for my program a...
While working with different versions of Python on Windows, I am using this method to switch between versions. I think it is better than messing with shebangs and virtualenvs 1) install python versions you desire 2) go to Environment Variables > PATH (i assume that paths of python versions are already added to Env.Var...
-0.050976
false
3
1,938
2012-06-23 15:46:23.330
How do I tell a Python script to use a particular version
How do I, in the main.py module (presumably), tell Python which interpreter to use? What I mean is: if I want a particular script to use version 3 of Python to interpret the entire program, how do I do that? Bonus: How would this affect a virtualenv? Am I right in thinking that if I create a virtualenv for my program a...
I had this problem and just decided to rename one of the programs from python.exe to python2.7.exe. Now I can specify on command prompt which program to run easily without introducing any scripts or changing environmental paths. So i have two programs: python2.7 and python (the latter which is v.3.8 aka default).
-0.050976
false
3
1,938
2012-06-24 21:07:07.857
Where should I declare a list of 5,000+ words?
I am writing a game in python in which I must periodically pull a random word from a list of words. When I prototyped my game I declared a word_list = ['cat','dog','rat','house'] of ten words at the top of one of my modules. I then use choice(word_list) to get a random word. However, I must must change this temporary h...
I would create a separated module called random_words, or something like that, hiding the list inside it and encapsulating the choice(word_list) inside an interface function. As to load them from a file, well, since I would need to type them anyway, and a python file is just a text file in the end, I would type them ri...
0.201295
false
2
1,939
2012-06-24 21:07:07.857
Where should I declare a list of 5,000+ words?
I am writing a game in python in which I must periodically pull a random word from a list of words. When I prototyped my game I declared a word_list = ['cat','dog','rat','house'] of ten words at the top of one of my modules. I then use choice(word_list) to get a random word. However, I must must change this temporary h...
Read the words from the file at startup (or at least the line indexes), and use as required.
0.296905
false
2
1,939
2012-06-27 00:39:01.710
Split quadrilateral into sub-regions of a maximum area
It is pretty easy to split a rectangle/square into smaller regions and enforce a maximum area of each sub-region. You can just divide the region into regions with sides length sqrt(max_area) and treat the leftovers with some care. With a quadrilateral however I am stumped. Let's assume I don't know the angle of any o...
You could recursively split the quad in half on the long sides until the resulting area is small enough.
0.201295
false
1
1,940
2012-06-27 09:27:35.880
Python + Sqlite 3. How to construct queries?
I'm trying to create a python script that constructs valid sqlite queries. I want to avoid SQL Injection, so I cannot use '%s'. I've found how to execute queries, cursor.execute('sql ?', (param)), but I want how to get the parsed sql param. It's not a problem if I have to execute the query first in order to obtain the ...
If you're not after just parameter substitution, but full construction of the SQL, you have to do that using string operations on your end. The ? replacement always just stands for a value. Internally, the SQL string is compiled to SQLite's own bytecode (you can find out what it generates with EXPLAIN thesql) and ? rep...
0.101688
false
3
1,941
2012-06-27 09:27:35.880
Python + Sqlite 3. How to construct queries?
I'm trying to create a python script that constructs valid sqlite queries. I want to avoid SQL Injection, so I cannot use '%s'. I've found how to execute queries, cursor.execute('sql ?', (param)), but I want how to get the parsed sql param. It's not a problem if I have to execute the query first in order to obtain the ...
If you're trying to transmit changes to the database to another computer, why do they have to be expressed as SQL strings? Why not pickle the query string and the parameters as a tuple, and have the other machine also use SQLite parameterization to query its database?
1.2
true
3
1,941
2012-06-27 09:27:35.880
Python + Sqlite 3. How to construct queries?
I'm trying to create a python script that constructs valid sqlite queries. I want to avoid SQL Injection, so I cannot use '%s'. I've found how to execute queries, cursor.execute('sql ?', (param)), but I want how to get the parsed sql param. It's not a problem if I have to execute the query first in order to obtain the ...
I want how to get the parsed 'sql param'. It's all open source so you have full access to the code doing the parsing / sanitization. Why not just reading this code and find out how it works and if there's some (possibly undocumented) implementation that you can reuse ?
0
false
3
1,941
2012-06-27 16:31:42.417
How to run a file that uses django models (large block of code) in Pycharm
So I have a chunk of code that declares some classes, creates data, uses django to actually save them to the database. My question is how do I actually execute it? I am using PyCharm and have the file open. But I have no clue how to actually execute it. I can execute line by line in Django Console, but if it's more tha...
If your site loads, you should put the import the models into one of your Django views. In a view you can do whatever you like with the models.
1.2
true
1
1,942
2012-06-27 16:48:05.277
how to do urlopen over ipv4 by default
What is the way to do urlopen in python such that even if the underlying machine has ipv6 networking enabled, the request is sent via ipv4 instead of ipv6?
I had a look into the source code. Unfortunately, urllib.urlopen() seems to use httplib.HTTP(), which doesn't even allow setting a source address. urllib2.urlopen() uses httplib.HTTPConnection() which you could inherit from and create a class which by default sets a source address '0.0.0.0' instead of ''. Then you coul...
0.386912
false
1
1,943
2012-06-29 18:57:08.857
Compiling Python modules on Windows x64
I'm starting out some projects in words processing and I needed NumPy and NLTK. That was the first time I got to know easy_install and how to compile new module of python into the system. I have Python 2.7 x64 plus VS 11 and VS 12. Also Cygwin (the latest one I guess). I could see in the file that compiles using VS tha...
there are several ways to do it apparently. build using mingw build python 2.7 using VS 2008 express. i'm not sure regarding which version is good to build 3.2 but it could be VS 2010. you can compile python x64 from source using your desired VS, but u'll have competability issues with other pre built packages.
0
false
1
1,944
2012-07-01 05:20:58.823
Finding a unique url from a large list of URLs in O(n) time in a single pass
Recently I was asked this question in an interview. I gave an answer in O(n) time but in two passes. Also he asked me how to do the same if the url list cannot fit into the memory. Any help is very much appreciated.
This is actually a classic interview question and the answer they were expecting was that you first sort the urls and then make a binary search. If it doesn't fit in memory, you can do the same thing with a file.
-0.081452
false
2
1,945
2012-07-01 05:20:58.823
Finding a unique url from a large list of URLs in O(n) time in a single pass
Recently I was asked this question in an interview. I gave an answer in O(n) time but in two passes. Also he asked me how to do the same if the url list cannot fit into the memory. Any help is very much appreciated.
If it all fits in memory, then the problem is simple: Create two sets (choose your favorite data structure), both initially empty. One will contain unique URLs and the other will contain URLs that occur multiple times. Scan the URL list once. For each URL, if it exists in the unique set, remove it from the unique set a...
1.2
true
2
1,945
2012-07-01 12:51:34.863
How do I center a wx.MessageDialog to the frame?
I've tried setting dlg.CenterOnParent() but that doesn't work. I assume it's because my MessageDialog is not setting the frame as the parent. In that case how would I do this?
When you create a wx widget, the normal pattern of the create function is wx.SomeUIObject(parent, id, ...). The parent could be set when you create the dialog.
1.2
true
1
1,946
2012-07-01 18:29:13.890
Test for existence of field in django class
Given a django class and a field name how can you test to see whether the class has a field with the given name? The field name is a string in this case.
For example: field_name_exists = field_name in ModelName._meta.get_all_field_names()
0.386912
false
1
1,947
2012-07-02 00:56:09.937
how to make youtube videos embed on your webpage when a link is posted
I have a website that gets a lot of links to youtube and similar sites and I wanted to know if there is anyway that I can make a link automatically appear as a video. Like what happens when you post a link to a video on facebook. You can play it right on the page. Is there a way to do this without users actually post...
Use this code when getting embed link from list value. In the template inside the iframe use below code src="{{results[0].video_link}}" "video_link" is the Field name.
0
false
1
1,948
2012-07-02 04:40:11.907
In Macvim with +python3 supported, which command should I use to execute the current file itself?
I just set up IDE env for Python 3. I was wondering how I can run the file being currently edited in vim. I remembered that the command was ":python %", but it did not work for Python 3. Thank you very much.
For Python 3, just simply execute :!python3 % Furthermore, you might also want to map it to a hotkey in your settings, like what I did: noremap <D-r> <esc>:w<CR>:!python3 %<CR> So that you can just press Command+r to execute the current code with Python 3 anytime (it will be saved automatically.
1.2
true
1
1,949
2012-07-02 05:46:46.370
New URL on django admin independent of the apps
I am using django 1.4 and Python 2.7. I just have a simple requirement where I have to add a new URL to the django admin app. I know how to add URLs which are for the custom apps but am unable figure out how to add URLs which are of the admin app. Please guide me through this. Basically the full URL should be something...
Just put your desired url mapping before the admin mapping in your root urls.py. The first match for the request will be taken, because django goes the url mappings from top to down. Just remember that you don't use an url the admin normally needs or provides because this will never match with a custom mapping in front...
0.545705
false
1
1,950
2012-07-02 07:50:54.253
How to compare image with python
I'm looking for an algorithm to compare two images (I work with python). I find the PIL library, numpy/scipy and opencv. I know how to transform in greyscale, binary, make an histogram, .... that's ok but I don't know what I have to do with the two images to say "yes they're similar // they're probably similar // they ...
If you want to check if they are binary equal you can count a checksum on them and compare it. If you want to check if they are similar in some other way , it will be more complicated and definitely would not fit into simple answer posted on Stack Overflow. It just depends on how you define similarity but anyway it wou...
0.135221
false
1
1,951
2012-07-02 14:30:46.833
Splitting a number pattern
I want to now how do i split a string like 44664212666666 into [44664212 , 666666] or 58834888888888 into [58834, 888888888] without knowing where the first occurrence of the last recurring digit occurs. so passing it to a function say seperate(str) --> [non_recurring_part, end_recurring digits]
Can't you just scan from the last character to the first character and stop when the next char doesn't equal the previous. Then split at that index.
0
false
1
1,952
2012-07-02 23:40:40.820
Shared memory between python processes
I'm trying to figure out a way to share memory between python processes. Basically there is are objects that exists that multiple python processes need to be able to READ (only read) and use (no mutation). Right now this is implemented using redis + strings + cPickle, but cPickle takes up precious CPU time so I'd lik...
If you don't want pickling, multiprocessing.sharedctypes might fit. It's a bit low-level, though; you get single values or arrays of specified types. Another way to distribute data to child processes (one way) is multiprocessing.Pipe. That can handle Python objects, and it's implemented in C, so I cannot tell you weth...
0.296905
false
1
1,953
2012-07-03 21:01:01.133
How to install the Django plugin for the Eric IDE?
I can't believe I have to ask this, but I have spent almost three hours looking for the answer. Anyway, I have Eric IDE 4 installed on my linux distro. I can't seem to download any plugins to the plugins repository. The only one I really want is the Django plugin so when I start a new project in Eric, the Django op...
In the Plugins dropdown menu click on Plugin repository... Make sure that the repository URL is: http://eric-ide.python-projects.org/plugins4/repository.xml and then click on update. The Django plugin will show up in the list of available plugins, click on it and then click the download button. That should download th...
0.673066
false
1
1,954
2012-07-04 07:59:23.693
algorithm - minimizing boolean expressions
I'm trying to write out a piece of code that can reduce the LENGTH of a boolean expression to the minimum, so the code should reduce the number of elements in the expression to as little as possible. Right now I'm stuck and I need some help =[ Here's the rule: there can be arbitrary number of elements in a boolean expr...
Unfortunately, most of the given suggestions may not actually give @turtlesoup what he/she is looking for. @turtlesoup asked for a way to minimize the number of characters for a given boolean expression. Most simplification methods don't target the number of characters as a focus for simplification. When it comes to...
0.067922
false
1
1,955
2012-07-04 12:56:16.093
How can I combine rows of data into a new table based on similar timestamps? (python/MySQL/PHP)
Not sure if the title is a great way to word my actual problem and I apologize if this is too general of a question but I'm having some trouble wrapping my head around how to do something. What I'm trying to do: The idea is to create a MySQL database of 'outages' for the thousands of servers I'm responsible for monito...
The most basic solution with the setup you have now would be to: Get a list of all events, ordered by server ID and then by time of the event Loop through that list and record the start of a new event / end of an old event for your new database when: the server ID changes the time between the current event and the pr...
0
false
1
1,956
2012-07-05 04:59:53.770
Python Multiprocessing: What's the difference between map and imap?
I'm trying to learn how to use Python's multiprocessing package, but I don't understand the difference between map and imap. Is the difference that map returns, say, an actual array or set, while imap returns an iterator over an array or set? When would I use one over the other? Also, I don't understand what the chunks...
That is the difference. One reason why you might use imap instead of map is if you wanted to start processing the first few results without waiting for the rest to be calculated. map waits for every result before returning. As for chunksize, it is sometimes more efficient to dole out work in larger quantities because e...
1.2
true
1
1,957
2012-07-05 09:05:35.373
In plone how can I make an uploaded file as NOT downloadable?
I wish to make the uploaded file contents only viewable on the browser i.e using atreal.richfile.preview for doc/xls/pdf files. The file should not be downloadable at any cost. How do I remove the hyperlink for the template in a particular folder for all the files in that folder? I use Plone 4.1 There is AT at_download...
Cue tune from Hotel California: "You can check out any time you like, but you can never leave." You do not not really want to disable all downloading, I believe that you really just want to disable downloads from all users but Owner. There is no practical use for putting files into something with no vehicle for EVER...
0.545705
false
2
1,958
2012-07-05 09:05:35.373
In plone how can I make an uploaded file as NOT downloadable?
I wish to make the uploaded file contents only viewable on the browser i.e using atreal.richfile.preview for doc/xls/pdf files. The file should not be downloadable at any cost. How do I remove the hyperlink for the template in a particular folder for all the files in that folder? I use Plone 4.1 There is AT at_download...
Script (Python) at /mysite/portal_skins/archetypes/at_download Just customize to contain nothing. Thought this will be helpful to someone who would like to keep files/ image files in Plone confidential by sharing the folders with view permission and disable checkout and copy option for the role created
1.2
true
2
1,958
2012-07-05 10:38:34.220
Check if wx.lib.scrolledpanel.ScrolledPanel is currently scrolling
I'm trying to use the ScrolledPanel in wx.lib.scrolledpanel, and i would like to check if the scrollbar of the ScrolledPanel is currently visible, so i can give my StaticText the correct wrap width. Because when the scrollbar is visible i need to remove another 10 pixels or so from the wrap width... Anyone any idea how...
I solved this by getting the width of the parent widget inside the scrolledpanel, instead of the width of the scrolledpanel itself. Sometimes the answer is so obvious :)
1.2
true
1
1,959
2012-07-05 17:30:21.783
How can I periodically run a Python script to import data into a Django app?
I have a script which scans an email inbox for specific emails. That part's working well and I'm able to acquire the data I'm interested in. I'd now like to take that data and add it to a Django app which will be used to display the information. I can run the script on a CRON job to periodically grab new information, b...
Forget about this being a Django app for a second. It is just a load of Python code. What this means is, your Python script is absolutely free to import the database models you have in your Django app and use them as you would in a standard module in your project. The only difference here, is that you may need to take ...
0.050976
false
4
1,960
2012-07-05 17:30:21.783
How can I periodically run a Python script to import data into a Django app?
I have a script which scans an email inbox for specific emails. That part's working well and I'm able to acquire the data I'm interested in. I'd now like to take that data and add it to a Django app which will be used to display the information. I can run the script on a CRON job to periodically grab new information, b...
I have done the same thing. Firstly, my script was already parsing the emails and storing them in a db, so I set the db up in settings.py and used python manage.py inspectdb to create a model based on that db. Then it's just a matter of building a view to display the information from your db. If your script doesn't alr...
0.050976
false
4
1,960
2012-07-05 17:30:21.783
How can I periodically run a Python script to import data into a Django app?
I have a script which scans an email inbox for specific emails. That part's working well and I'm able to acquire the data I'm interested in. I'd now like to take that data and add it to a Django app which will be used to display the information. I can run the script on a CRON job to periodically grab new information, b...
Best way? Make a view on the django side to handle receiving the data, and have your script do a HTTP POST on a URL registered to that view. You could also import the model and such from inside your script, but I don't think that's a very good idea.
0
false
4
1,960
2012-07-05 17:30:21.783
How can I periodically run a Python script to import data into a Django app?
I have a script which scans an email inbox for specific emails. That part's working well and I'm able to acquire the data I'm interested in. I'd now like to take that data and add it to a Django app which will be used to display the information. I can run the script on a CRON job to periodically grab new information, b...
When you are saying " get that data into the DJango app" what exactly do you mean? I am guessing that you are using some sort of database (like mysql). Insert whatever data you have collected from your cronjob into the respective tables that your Django app is accessing. Also insert this cron data into the same tables...
0
false
4
1,960
2012-07-05 17:46:17.607
Scraper Google App Engine for Steam
So basically, at the moment, we are trying to write a basic HTML 5 page that, when you press a button, returns whether the user, on Steam, is in-game, offline, or online. We have looked at the Steam API, and to find this information, it requires the person's 64 bit ID (steamID64) and we, on the website, are only given ...
Since you have the steam id from the service you can then make another request to their steam community page via the id. From there you can use beautiful soup to return a dom to grab the required information for your project. Now onto your question. You can have all this happen within a request in a handler, if you a...
0.201295
false
1
1,961
2012-07-06 11:39:26.407
Python app design patterns - instance must be available for most other instances
I'm writing pretty big and complex application, so I want to stick to design patterns to keep code in good quality. I have problem with one instance that needs to be available for almost all other instances. Lets say I have instance of BusMonitor (class for logging messages) and other instances that use this instance f...
I want to keep things in classes to retain consistency Why? Why is consistency important (other than being a hobgoblin of little minds)? Use classes where they make sense. Use modules where they don't. Classes in Python are really for encapsulating data and retaining state. If you're not doing those things, don't use ...
0.386912
false
2
1,962
2012-07-06 11:39:26.407
Python app design patterns - instance must be available for most other instances
I'm writing pretty big and complex application, so I want to stick to design patterns to keep code in good quality. I have problem with one instance that needs to be available for almost all other instances. Lets say I have instance of BusMonitor (class for logging messages) and other instances that use this instance f...
I found good way I think. I made module with class BusMonitor, and in the same module, after class definition I make instance of this class. Now I can import it from everywhere in project and I retain consistency using classes and encapsulation.
1.2
true
2
1,962
2012-07-06 23:51:52.470
Profiling Python via C-api (How to ? )
I have used the Python's C-API to call some Python code in my c code and now I want to profile my python code for bottlenecks. I came across the PyEval_SetProfile API and am not sure how to use it. Do I need to write my own profiling function? I will be very thankful if you can provide an example or point me to an ex...
If you only need to know the amount of time spent in the Python code, and not (for example), where in the Python code the most time is spent, then the Python profiling tools are not what you want. I would write some simple C code that sampled the time before and after the Python interpreter invocation, and use that. ...
1.2
true
1
1,963
2012-07-08 01:03:47.360
How do I change the font size of the scale in matplotlib plots?
While plotting using Matplotlib, I have found how to change the font size of the labels. But, how can I change the size of the numbers in the scale? For clarity, suppose you plot x^2 from (x0,y0) = 0,0 to (x1,y1) = (20,20). The scale in the x-axis below maybe something like 0 1 2 ... 20. I want to change the ...
simply put, you can use the following command to set the range of the ticks and change the size of the ticks import matplotlib.pyplot as plt set the range of ticks for x-axis and y-axis plt.set_yticks(range(0,24,2)) plt.set_xticks(range(0,24,2)) change the size of ticks for x-axis and y-axis plt.yticks(fontsize=12,) pl...
0
false
1
1,964
2012-07-09 05:04:13.100
Python Sub-process (Output PIPE)
How can I read from output PIPE multiple times without using process.communicate() as communicate closes the PIPE after reading the output but I need to have sequential inputs and outputs. For example, 1) process.stdin.write('input_1') 2) After that, I need to read the output PIPE (how can I accomplish that without usi...
Instead of process.communicate(), use process.stdout.read()
0
false
2
1,965
2012-07-09 05:04:13.100
Python Sub-process (Output PIPE)
How can I read from output PIPE multiple times without using process.communicate() as communicate closes the PIPE after reading the output but I need to have sequential inputs and outputs. For example, 1) process.stdin.write('input_1') 2) After that, I need to read the output PIPE (how can I accomplish that without usi...
flush() stdin, then read() stdout.
0.201295
false
2
1,965
2012-07-09 09:26:37.047
Getting ejabberd to notify an external module on client presence change
I have an ejabberd server at jabber.domain.com, with an xmpp component written in python (using sleekxmpp) at presence.domain.com. I wanted the component to get a notification each time a client changed his presence from available to unavailable and vice-versa. The clients themselves don't have any contacts. Currently,...
It is possible for a component to subscribe to a user's presence exactly the same way a user does. Also it is possible for the user to subscribe to a component's presence. You just have to follow the usual pattern, i.e. the component/user sends a <presence/> of type subscribe which the user/component can accept by send...
0
false
2
1,966
2012-07-09 09:26:37.047
Getting ejabberd to notify an external module on client presence change
I have an ejabberd server at jabber.domain.com, with an xmpp component written in python (using sleekxmpp) at presence.domain.com. I wanted the component to get a notification each time a client changed his presence from available to unavailable and vice-versa. The clients themselves don't have any contacts. Currently,...
It is not difficult to write a custom ejabberd module for this. It will need to register to presence change hooks in ejabberd, and on each presence packet route a notification towards your external component. There is a pair of hooks 'set_presence_hook' and 'unset_presence_hook' that your module can register to, ...
1.2
true
2
1,966
2012-07-10 00:11:22.507
Embed .exe in wxpython
I am looking for a way to embed an .exe into a frame. (MDI) I am not sure how this can be done. I am using wxpython 2.9 and there is nothing online about this (until now).
Embedding one GUI application inside another is not a simple thing. Applications are written to provide their own main frame, for example. You could try to position Notepad to a particular place on the screen instead. If you're really talking about Notepad, then you have a different course of action. Notepad is noth...
0
false
1
1,967
2012-07-10 03:11:24.307
Integrating multiple dictionaries in python (big data)
I am working on a research project in big data mining. I have written the code currently to organize the data I have into a dictionary. However, The amount of data is so huge that while forming the dictionary, my computer runs out of memory. I need to periodically write my dictionary to main memory and create multiple ...
First thought - switch to 64-bit python and increase your computer's virtual memory settings ;-) Second thought - once you have a large dictionary, you can sort on key and write it to file. Once all your data has been written, you can then iterate through all the files simultaneously, comparing and writing out the fina...
0
false
2
1,968
2012-07-10 03:11:24.307
Integrating multiple dictionaries in python (big data)
I am working on a research project in big data mining. I have written the code currently to organize the data I have into a dictionary. However, The amount of data is so huge that while forming the dictionary, my computer runs out of memory. I need to periodically write my dictionary to main memory and create multiple ...
You should use a database such as PostgreSQL.
0
false
2
1,968
2012-07-10 10:17:20.313
How to find x and y-offset for slider in python for a web-application
Can anyone please tell me how to find the x-offset and y-offset default value of a Slider in a webpage using python for selenium webdriver. Thanks in Advance !
You can use the get_attribute(name) method on a webelement to retrieve attributes.
0
false
1
1,969
2012-07-10 18:59:09.253
executing c program from a python program
I'm new to programming and was wondering how I can have a python program execute and communicate with a c program. I am doing a mathematical computation in python, and was wondering if I could write up the main computation in C, that way the computation runs faster. I've been reading about "calling c functions from pyt...
There's also numpy which can be reasonably fast when dealing with "array operations" (sometimes called vector operations, but I find that term confusing with SIMD terminology). You'll probably need numpy if you decide to go the cython route, so if the algorithm isn't too complicated, you might want to see if it is goo...
0.201295
false
1
1,970
2012-07-10 20:32:43.337
Integrate networkx in eclipse on windows
I'm using PyDev in eclipse with Python 2.7 on windows 7. I Installed networkx and it is properly running within Python shell but in eclipse it is showing error as it is unable to locate networkx can anyone tell me how to remove this error?
you need to rebuild your interpreter go to project > properties > pyDev-Interpreter/Grammar click the "click here to configure" remove the existing interpreter hit "Auto config" button and follow the prompts kind of a pain but the only way Ive found to autodiscover newly installed packages
1.2
true
2
1,971
2012-07-10 20:32:43.337
Integrate networkx in eclipse on windows
I'm using PyDev in eclipse with Python 2.7 on windows 7. I Installed networkx and it is properly running within Python shell but in eclipse it is showing error as it is unable to locate networkx can anyone tell me how to remove this error?
I think there are two options: Rebuild your interpreter Add it to your python path by appending the location of networkx to sys.path in python
0
false
2
1,971
2012-07-11 06:57:11.423
how to darw the image faster in canvas
I am capturing mobile snapshot(android) through monkeyrunner and with the help of some python script(i.e. for socket connection),i made it to display in an html page.but there is some time delay between the image i saw on my browser and that one on the android device.how can i synchronise these things so that the mobil...
It takes time for the image to get from your phone to your server to your desktop client. There's nothing you can do to change that. The best you can hope to do is to benchmark your entire application, figure out where are your bottlenecks, and hope it's not the network connection itself.
0.386912
false
1
1,972
2012-07-11 23:18:23.010
python handling subprocess
I am running an os.system(cmd) in a for-loop. Since sometimes it hangs, I am trying to use process=subprocess.pOpen(cmd) in a for-loop. But I want to know the following: If I do sleep(60) and then check if the process is still running by using process.poll(), how do I differentiate between process actually running eve...
A common way to detect things that have stopped working is to have them emit a signal at roughly regular intervals and have another process monitor the signal. If the monitor sees that no signal has arrived after, say, twice the interval it can take action such as killing and restarting the process. This general idea ...
0
false
2
1,973
2012-07-11 23:18:23.010
python handling subprocess
I am running an os.system(cmd) in a for-loop. Since sometimes it hangs, I am trying to use process=subprocess.pOpen(cmd) in a for-loop. But I want to know the following: If I do sleep(60) and then check if the process is still running by using process.poll(), how do I differentiate between process actually running eve...
I don't know of any general way to tell whether a process is hung or working. If a process hangs due to a locking issue, then it might consume 0% CPU and you might be able to guess that it is hung and not working; but if it hangs with an infinite loop, the process might make the CPU 100% busy but not accomplish any us...
1.2
true
2
1,973
2012-07-12 04:47:02.677
Django Access File on Server
I'm using Django to send iOS push notifications. To do that, I need to access a .pem certificate file currently stored on the server in my app directory along with views.py, models.py, admin.py, etc. When I try to send a push notification from a python shell on the server, everything works fine. But when I try to se...
Never mind, I tried it again using an absolute file path, and it worked after I restarted Django.
0.386912
false
1
1,974
2012-07-12 21:20:27.727
how to use CustomTreeCtrl with the TR_HAS_VARIABLE_ROW_HEIGHT style to change the items height?
I gave my CustomTreeCtrl the TR_HAS_VARIABLE_ROW_HEIGHT style. But I am not sure where to go from there to change the height of the items inside the tree. I cant really find anything on the API or online.
I think all you have to do is change the font size of the item. That's what it looks like in the wxPython demo anyway. You could ask on the wxPython users group though. The author of that widget is on there most of the time and is very helpful.
1.2
true
1
1,975
2012-07-13 12:49:12.137
Recive REST and Response http codes in Python
I want to make very simple application in Python which: When REST calls PUT/DEL/GET are recived than response code is 200 When REST call create is recived than response code is 201 I tried with sockets but I don't know how to send 201.
Use an existing web framework such as Flask or Django. Doing this by yourself with sockets is way too much work, it's not worth it.
1.2
true
1
1,976
2012-07-13 14:45:09.987
How to specify version ranges in install_requires (setuptools, distribute)
I want to make a package to depend the particular version range e.g. >= 0.5.0, < 0.7.0. Is it possible in install_requires option, and if so how should it be?
Another way to it is to use wildcards. This does not apply to >= 0.5.0, < 0.7.0, but in case you decide that all maintenance releases should be supported (e.g. 0.5.0 to 0.5.x), you can use == 0.5.* e.g. docutils == 0.3.*
0.16183
false
1
1,977
2012-07-13 18:06:14.570
IronPython launching very slowly
I am launching IronPython 2.7.3 on Windows 7 and it is taking more than 15 seconds. Why is it so slow? And how to fix it? The computer is a Samsung NP300E5A(Celeron B800,2gb) notebook.
There are a few reason why IronPython is slow to startup. First, if you didn't use the installer (which will ngen the assemblies), the JIT compiler has to convert the IronPython assemblies from MSIL bytecode to native code, and that takes time, as it's a lot of code. So use the installer on manually ngen the assemblies...
1.2
true
1
1,978
2012-07-14 00:33:54.570
Python get list of all enclosing files
I have been at this for a few hours... how to use python to get all enclosing files from a folder... now by enclosing I mean all the files enclosed within a folder within a folder etc. So all the files beyond a certain point using Python. I have tried to use glob.glob() and listdir() to do this, but those will just on...
You want os.walk(). It will give you a list of files and folders in each directory under the starting directory.
1.2
true
1
1,979
2012-07-16 02:14:11.033
How do I specify new lines on Python, when writing on files?
In comparison to Java (in a string), you would do something like "First Line\r\nSecond Line". So how would you do that in Python, for purposes of writing multiple lines to a regular file?
Most escape characters in string literals from Java are also valid in Python, such as "\r" and "\n".
0.108416
false
3
1,980
2012-07-16 02:14:11.033
How do I specify new lines on Python, when writing on files?
In comparison to Java (in a string), you would do something like "First Line\r\nSecond Line". So how would you do that in Python, for purposes of writing multiple lines to a regular file?
In Python you can just use the new-line character, i.e. \n
0.265586
false
3
1,980
2012-07-16 02:14:11.033
How do I specify new lines on Python, when writing on files?
In comparison to Java (in a string), you would do something like "First Line\r\nSecond Line". So how would you do that in Python, for purposes of writing multiple lines to a regular file?
The same way with '\n', though you'd probably not need the '\r'. Is there a reason you have it in your Java version? If you do need/want it, you can use it in the same way in Python too.
0.16183
false
3
1,980
2012-07-16 13:20:21.190
Python web framework suggestion for a web service
I'm gonna write a web service which will allow upload/download of files, managing permissions and users. It will be the interface to which a Desktop app or Mobile App will communicate. I was wondering which of the web frameworks I should use to to that? It is a sort of remote storage for media files. I am going to host...
I'm no doubt going to be shot down for this answer, but it needs to be said... You're going to write a service that allows tens of transfers a second, with very large file sizes... Uptime is going to be essential and so is transfer speeds etc... If this is for a business, and not just a personal pet project get the per...
1.2
true
1
1,981