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
2010-06-24 13:05:53.847
Django Template Ternary Operator
I was wondering if there was a ternary operator (condition ? true-value : false-value) that could be used in a Django template. I see there is a python one (true-value if condition else false-value) but I'm unsure how to use that inside a Django template to display the html given by one of the values. Any ideas?
You don't. The Django {% if %} templatetag has only just started supporting ==, and, etc. {% if cond %}{% else %}{% endif %} is as compact as it gets for now.
0.327599
false
1
637
2010-06-25 12:35:52.680
How can I use common code in python?
I'm currently maintaining two of my own applications. They both share some common aspects, and as a result, share some code. So far, I've just copied the modules from one project to the other, but now it's becoming a maintenance issue. I'd rather have the common code in one place, outside of both of the projects, which...
There are a lot of ways to factor code so it is reusable. It really depends on your specific situation as far as what will work best. Factoring your code into separate packages and modules is always a good idea, so related code stays bundled together and can be reused from other packages and modules. Factoring your ...
0.496174
false
1
638
2010-06-26 00:55:29.283
GUI layout -how?
I've been working with a few RAD gui builders lately. I absolutely despise CSS ( camel is a horse designed by committee etc.) What algorithms are used by packing managers(java/tk). Most GUI toolkits I've used have some alternative to absolute positioning, sorry for the ambiguity but how do you start thinking about impl...
Tk has three methods. One is absolute positioning, the other two are called "grid" and "pack". grid is just what it sounds like: you lay out your widgets in a grid. There are options for spanning rows and columns, expanding (or not) to fill a cell, designating rows or columns which can grow, etc. You can accomplish pr...
0.995055
false
1
639
2010-06-27 02:19:40.497
What should I use for the backend of a 'social' website?
My two main requirements for the site are related to degrees of separation and graph matching (given two graphs, return some kind of similarity score). My first thought was to use MySql to do it, which would probably work out okay for storing how I want to manage 'friends' (similar to Twitter), but I'm thinking if I wa...
MySQL is really your best choice for the database unless you want to go proprietary. As for the actual language, pick whatever you are familiar with. While Youtube and Reddit are written in python, many of the other large sites use Ruby (Hulu, Twitter, Techcrunch) or C++ (Google) or PHP (Facebook, Yahoo, etc).
0.201295
false
1
640
2010-06-27 08:17:07.493
Getting size of Gtk.Table in python
I am having a problem with widget Gtk.Table - I would like to know, if there is a way how to get a current size of the table (number of rows and columns). Thank you, very much for help, Tomas
In most recent versions of PyGTK you can get/set those values via table.props.n_columns and table.props.n_rows, which is synonymous with the get_property() (mentioned in the other answers) and set_property() methods.
0
false
1
641
2010-06-27 09:36:21.520
URLs and side effects (Django)
I'm wondering if it's considered okay (particularly, in Django) to have a URL that's only intended for actions with side effects, that's only intended to be accessed by POST, and that is basically invisible to the user. Let's say, for the sake of making this concrete, I have a little messaging system on my site, and fr...
A modified option #1 is the best approach. Consider this: suppose we weren't talking about a web app, but instead were just designing an inbox class. Which do you like better, a number of methods (delete_message(), mark_as_spam(), etc), or one big method (do_stuff(action))? Of course you would use the separate metho...
1.2
true
4
642
2010-06-27 09:36:21.520
URLs and side effects (Django)
I'm wondering if it's considered okay (particularly, in Django) to have a URL that's only intended for actions with side effects, that's only intended to be accessed by POST, and that is basically invisible to the user. Let's say, for the sake of making this concrete, I have a little messaging system on my site, and fr...
I agree that #2 is a better approach. But take care with overloading the submit <input /> with different methods -- if a user is using it with keyboard input and hits enter, it won't necessarily submit the <input /> you're expecting. Either disable auto-submit-on-enter, or code things up so that if there is more than ...
0
false
4
642
2010-06-27 09:36:21.520
URLs and side effects (Django)
I'm wondering if it's considered okay (particularly, in Django) to have a URL that's only intended for actions with side effects, that's only intended to be accessed by POST, and that is basically invisible to the user. Let's say, for the sake of making this concrete, I have a little messaging system on my site, and fr...
If you're writing a web 2.0 messaging app, you would be using AJAX calls and wouldn't be loading a new page at all. The process would proceed like so: User clicks [delete] for a message. This button has a javascript action bound to it. This action does the following: i. Change the UI to indicate that something is happ...
0.101688
false
4
642
2010-06-27 09:36:21.520
URLs and side effects (Django)
I'm wondering if it's considered okay (particularly, in Django) to have a URL that's only intended for actions with side effects, that's only intended to be accessed by POST, and that is basically invisible to the user. Let's say, for the sake of making this concrete, I have a little messaging system on my site, and fr...
I don't think there's anything wrong with either option, but #2 is potentially better from a performance standpoint. After the action is posted you can render the inbox without a redirect, so it cuts down on the HTTP traffic.
0.101688
false
4
642
2010-06-27 16:07:43.173
Is it possible to run two versions of Python side-by-side?
I've been learning Python for a couple of weeks, and although I've been successfully develop apps for Google App Engine with Python 2.6.5, it specifically requires Python 2.5. Being mindful of compatibility issues when uploading apps (it's a situation I'd rather avoid while learning Python), I wonder if it's possible t...
Absolutely. If you're on *nix, you'd usually just use make altinstall instead of make install, that way the "python" binary won't get installed/overwritten, but instead you'd have e.g. python2.5 or python2.6 installed. Using a separate --prefix with the configure script is also an option, of course. Some Linux distribu...
0.591696
false
2
643
2010-06-27 16:07:43.173
Is it possible to run two versions of Python side-by-side?
I've been learning Python for a couple of weeks, and although I've been successfully develop apps for Google App Engine with Python 2.6.5, it specifically requires Python 2.5. Being mindful of compatibility issues when uploading apps (it's a situation I'd rather avoid while learning Python), I wonder if it's possible t...
OK, I figured out the answer to my own question, partly with the help of Nicholas Knight who pointed out that you just install different Python version to different Python directories. I was left scratching my head on how to get Google App Engine to use Python 2.5 (the required version) instead of Python 2.6. This is...
0
false
2
643
2010-06-28 11:38:11.187
How to 'catch' c printf in python with ctypes?
I hope this is trivial and I just didn't find it in the tutorials. I am writing python code that 'supervises' c code, aka I run the c code with ctypes from python. Now I want to 'catch' the c 'printfs' to process the data that is output by the c code. Any idea how one would do this? Thanks
Well printf simply writes its output to whatever the stdout file pointer refers to. Im not sure how you're executing the C program, but it should be possible to redirect the C program's stdout to something that you can read in Python.
0
false
1
644
2010-06-28 21:52:50.213
Trying to install Django via Macports on Leopard
I have Python 2.6 & 3.1 installed on Leopard via mac ports with no problems. I want to install Django 1.2 via mac ports for Python 2.6, but a google search of how to do it seems to point me in the wrong direction. Can anyone point me in the right direction? Thanks again.....
Just "throw" the django tarball within the site-packages (dist-packages in py2.6+) and you are done. What for do you need macports etc, with a pure python library?
0
false
1
645
2010-06-30 07:29:29.517
Python library installing macports
I would like to install: A. Mod python on a regular Macbookpro (MacOSX 10.6.4) B. And MySQL for Python on the same computer. And the installation is constantly failing. Question 1: Is there a tutorial on how to achieve this on Mac OS? I also hoped that I could use Macports for this. I had bad experience with Macports...
This answer is outdated, see Mark's response below I had trouble installing python and python libraries on osx, and this is what I ended up doing to fix it: Using macports I installed python26 and python_select. Then use python_select to change from the default python26-apple to python26 (which is from macports). Now w...
0
false
1
646
2010-06-30 07:38:28.763
how to detect bounce mail in google app engine?
sometime due to wrong input from user side, mail bounce and did not reach the recipient. ( sent from google app engine.) How to detect such email ? edit: may be i was not clear in my question : I want to know to which mail i have sent the mail which was return ( so that i may alert the user or delete the email id ). ...
easiest is to encode an email address via base64 or simiar encoding and prefixed it to from address. all address from something@myapp.appspotmail.com are valid email address for from in gae. simply create a mail receive handler. decode the from string and get the email address to whom you send the email originally. sa...
1.2
true
1
647
2010-06-30 10:50:13.183
Py2exe Directory Structure
I use Py2exe to package a Python application with quite a few dependant packages. While Py2exe works flawlessly the resulting dist/ folder with the executable contains a large number (10-15) of support files (.dll, .pyd, .zip). Ideally I would like to be able to place all of these dependant files in a folder called sup...
An effective solution is to bundle everything in an standalone executable using bundle_files:1 in your setup.py py2exe options.
1.2
true
1
648
2010-07-01 06:52:22.183
Is Django admin difficult to customize?
I have been playing for a couple of days with Django Admin to explore it, but I am still clueless of how it can be customized in the way we need. Every time I look for any help for the customization in the admin panel, what I find is, a bunch of articles on various communities and forums, explaining how to customize t...
Django Admin is easy to customize if your requirements match what is customizable in Django. If you need fancy features that are not out-of-the-box functionality you either need to find a plugin that does it, or implement it yourself by subclassing the appropriate classes. Which can be difficult, and requires good unde...
0.101688
false
2
649
2010-07-01 06:52:22.183
Is Django admin difficult to customize?
I have been playing for a couple of days with Django Admin to explore it, but I am still clueless of how it can be customized in the way we need. Every time I look for any help for the customization in the admin panel, what I find is, a bunch of articles on various communities and forums, explaining how to customize t...
Personally, if you want a site to look like the admin, why not pull the templates and styles and use them, build your own views for what you need. Gobs of documentation and forum help is there for that. I like the idea of customizing the admin, but honestly, I have been doing it for awhile on a project and time and t...
0.296905
false
2
649
2010-07-01 12:45:13.863
Logging activity on Django's admin - Django
I need to track/log activity on the Django admin. I know there are messages stored by admin somewhere, but I don't know how to access them in order to use them as a simple log. I'm trying to track the following: User performing the action Action committed Datetime of action Thanks guys.
Log is in django_admin_log table in database used by django.
0.999976
false
1
650
2010-07-01 18:39:36.657
Python Progress Bar
How do I use a progress bar when my script is doing some task that is likely to take time? For example, a function which takes some time to complete and returns True when done. How can I display a progress bar during the time the function is being executed? Note that I need this to be in real time, so I can't figure ou...
You should link the progress bar to the task at hand (so that it measures the progress :D). For example, if you are FTPing a file, you can tell ftplib to grab a certain size buffer, let's say 128K, and then you add to your progress bar whatever percentage of the filesize 128k represents. If you are using the CLI, and y...
0
false
1
651
2010-07-02 16:27:38.730
Rename a computer programmatically
I need to automate the changing of the hostname of a computer, but I can't figure out how to do it inside a program. My options are open; I would be happy with a solution in any of the following: Command line Java Python C# (would prefer one of the other 3, but this is ok) It would be helpful to learn how to do this on...
In Windows you have to modify registry keys and the reboot the system. You actually have to change two entries: HostName under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TcpIp\Parameters and ComputerName under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName Please note that if th...
0
false
1
652
2010-07-03 14:40:02.600
Python: how do you remember the order of `super`'s arguments?
As the title says, how do you remember the order of super's arguments? Is there a mnemonic somewhere I've missed? After years of Python programming, I still have to look it up :( (for the record, it's super(Type, self))
Simply remember that the self is optional - super(Type) gives access to unbound superclass methods - and optional arguments always come last.
0.986614
false
1
653
2010-07-03 19:03:04.737
How to draw a spherical triangle on a sphere in 3D?
Suppose you know the three vertices for a spherical triangle. Then how do you draw the sides on a sphere in 3D? I need some python code to use in Blender 3d modelisation software. I already have the sphere done in 3D in Blender. Thanks & happy blendering. note 1: i have the 3 points / vertices (p1,p2,p3 ) on the sphe...
One cheap and easy method for doing this would be to create the triangle and subdivide the faces down to the level of detail you want, then normalize all the vertices to the radius you want.
0
false
1
654
2010-07-03 22:26:44.273
How to create a self contained Python Qt app on mac
I've recently started using a mac, and I'm curious about how to make a mac app that uses PyQt and is self-contained. Can anyone give me any pointers on where to start and what I'll need?
I've tried the same for some weeks now. Finally i have to say py2app just wont do. I was lucky with pyinstaller1.4. Although you need to add some minor modifications to run flawlessly on OS X. Furthermore the apps it creates are only 1/4 of the size compared to py2app. And most important it works :) And yet another goo...
0.135221
false
1
655
2010-07-03 23:14:15.623
Move an item inside a list?
In Python, how do I move an item to a definite index in a list?
I profiled a few methods to move an item within the same list with timeit. Here are the ones to use if j>i: ┌──────────┬──────────────────────┐ │ 14.4usec │ x[i:i]=x.pop(j), │ │ 14.5usec │ x[i:i]=[x.pop(j)] │ │ 15.2usec │ x.insert(i,x.pop(j)) │ └──────────┴──────────────────────┘ and here the ones to use if j<=...
0.050976
false
1
656
2010-07-04 10:28:39.980
How to design a twisted solution to download a file by reading on certain portion?
How do I download a remote file into several chunks using twisted? Lets say if the file is 100 bytes, I want to spawn 10 connection which will read 10 bytes each but in no particular order and then later on merge them all. I was able to do this using threads in Python but I don't have any idea how to use twisted's reac...
I don't think this really provides the direction the user requires - the question seems to be clear in how to use Twisted to achieve this - the answer implies reasonable knowledge of Twisted.
0
false
1
657
2010-07-05 03:02:25.057
Controlling Linux Compiz Brightness Programmatically with Python or Vala
Several laptops on the market have problems with Linux for brightness controls. However, recently I found out that you can use CompizConfig settings to dim at least a particular window. Many people, however, want to dim all windows. I know Compiz can do this in the API somewhere because look what happens when you do Su...
You want to look into gnome-compiz especially into gtk-window-decorator and gnome-xgl-settings.
0.386912
false
1
658
2010-07-05 12:34:49.890
making paint in pyqt or qt
i have just received a task to implement a software that paints over pictures (pretty much like microsoft paint ) i have no idea where to start or how to do that. do anyone have a good reference or idea for painting in qt or pyqt ? this will be highly appreciated thanks in advance
Have you looked at the scribble example included in PyQt? It does basic drawing, saving, loading, etc.
0
false
1
659
2010-07-06 04:03:46.543
Where to store field data and how to provide access to it?
Forms have Fields, Fields have a value. However, they only get a value after the form has been submitted. How should I store this value? Should I give every field a value attribute, field.value, leave it as None prior to posting, and fill it in afterwords? Omit it completely, and dynamically add it? Store it on t...
It really depends on how you interact with the structures in question. Do you manipulate Form and Field objects prior to assigning them values? Do you need to frequently iterate over all the given Fields? Do you need Form once it's been submitted? Etc. I'd suggest writing some/all of the code that uses Form and figure ...
1.2
true
1
660
2010-07-06 20:51:20.883
Python: how to print range a-z?
1. Print a-n: a b c d e f g h i j k l m n 2. Every second in a-n: a c e g i k m 3. Append a-n to index of urls{hello.com/, hej.com/, ..., hallo.com/}: hello.com/a hej.com/b ... hallo.com/n
This is your 2nd question: string.lowercase[ord('a')-97:ord('n')-97:2] because 97==ord('a') -- if you want to learn a bit you should figure out the rest yourself ;-)
0.022672
false
1
661
2010-07-07 10:07:00.933
AdaBoost ML algorithm python implementation
Is there anyone that has some ideas on how to implement the AdaBoost (Boostexter) algorithm in python? Cheers!
Thanks a million Steve! In fact, your suggestion had some compatibility issues with MacOSX (a particular library was incompatible with the system) BUT it helped me find out a more interesting package : icsi.boost.macosx. I am just denoting that in case any Mac-eter finds it interesting! Thank you again! Tim
1.2
true
1
662
2010-07-07 23:40:06.893
pydev and twisted framework
It seems like my Eclipse PyDev does not recognize that Twisted is installed on my system. I can't make auto suggest working. Does anyone know how to solve it?
go to preferences->Pydev->Interpreter - Python and hit the apply button. That will rescan your modules directory and add any missing modules. That should fix any normal import errors. Some modules do some runtime magic that PyDev cant follow.
1.2
true
1
663
2010-07-09 17:26:45.087
Interact with Flash using Python Mechanize
I am trying to create an automated program in Python that deals with Flash. Right now I am using Python Mechanize, which is great for filling forms, but when it comes to flash I don't know what to do. Does anyone know how I can interact with flash forms (set and get variables, click buttons, etc.) via Python mechanize ...
Nice question but seems unfortunately mechanize can't be used for flash objects
0
false
1
664
2010-07-10 15:25:02.797
Updating my program, using a diff-based patch approach
Currently my program updates itself by downloading the latest .tar.gz file containing the source code, and extracting it over the current directory where the program lives. There are 2 "modes" of update - one for users running the Python source, and one if the user is running the program as a Windows exe. Over time my...
Your update manager can know which version the current app is, and which version is the most recent one and apply only the relevant patches. Suppose the user runs 0.38, and currently there is 0.42 available. The update for 0.42 contains patches for 0.39, 0.40, 0.41 and 0.42 (and probably farther down the history). The ...
0.201295
false
1
665
2010-07-10 17:55:47.210
How do I install an old version of Django on virtualenv?
I want to install some specific version of a package (in this case Django) inside the virtual environment. I can't figure it out. I'm on Windows XP, and I created the virtual environment successfully, and I'm able to run it, but how am I supposed to install the Django version I want into it? I mean, I know to use the n...
pip install "django>=2.2,<3" To install djnago 2.2
0.16183
false
1
666
2010-07-12 13:44:21.297
how to write a Python debugger/editor
Sorry for the kind of general question. More details about what I want: I want the user to be able to write some Python code and execute it. Once there is an exception which is not handled, I want the debugger to pause the execution, show information about the current state/environment/stack/exception and make it possi...
From what I have figured out in the meantime, this is not possible. At least not block-wise. It is possible to recompile the code per function but not per code-block because Python generates the code objects per function. So the only way is to write an own Python compiler.
0.135221
false
1
667
2010-07-14 14:35:52.973
Choosing a random file from a directory (with a large number of files) in Python
I have a directory with a large number of files (~1mil). I need to choose a random file from this directory. Since there are so many files, os.listdir naturally takes an eternity to finish. Is there a way I can circumvent this problem? Maybe somehow get to know the number of files in the directory (without listing it) ...
I'm not sure this is even possible. Even at the VFS or filesystem level, there is no guarantee that a directory entry count is even maintained. For instance many filesystems simply record the combined byte size of the directory entry structures contained in a given directory. Estimation may be made if directory entries...
0.081452
false
1
668
2010-07-15 05:34:58.053
List formation in python
I need to put 3 items in the list. state..eg(1,2) action...eg..west cost....5 list=[(state,action,cost), (state,action,cost).........] how can i make it in a form of list. For a particular state , action and cost is there. Moreover, if i need only state from the list, i should be able to extract it from the list.same...
The code you listed above is a list of tuples - which pretty much matches what you're asking for. From the example above, list[0][0] returns the state from the first tuple, list[0][1] the action, and list[0][2] the cost. You can extract the values with something like (state, action, cost)= list[i] too.
0
false
1
669
2010-07-16 10:06:52.577
Multiple Python Installations of the same python version on a single computer
I want to install the new Python 2.7 on my Windows XP 32bit PC. having CDO (thats OCD with initials sorted in alphabetical order) I want to install it multiple times on the same computer (to different TARGETDIRs). how do i do that ? double clicking on the installer, or running msiexec multiple times did not work for me...
Based on one of your comments, it looks like you don't actually need to install it, you just need it on the computer so your program can run. In that case you can take a page from Dropbox's book and include the interpreter, DLL, and standard library in one of your directories, and just use it from there.
0
false
1
670
2010-07-16 16:40:57.200
Recommendation for click/event tracking mechanisms (python, django, celery, mongo etc)
I'm looking into way to track events in a django application (events would generally be clicks tied to a specific unique user id). These events would essentially contain an event type like "click" and then each click event would be assigned to a unique id (many events can go to one id) and each event would have a data ...
If by click, you mean a click on a link that loads a new page (or performs an AJAX request), then what you aim to do is fairly straightforward. Web servers tend to keep plain-text logs about requests - with information about the user, time/date, referrer, the page requested, etc. You could examine these logs and mine t...
0.135221
false
2
671
2010-07-16 16:40:57.200
Recommendation for click/event tracking mechanisms (python, django, celery, mongo etc)
I'm looking into way to track events in a django application (events would generally be clicks tied to a specific unique user id). These events would essentially contain an event type like "click" and then each click event would be assigned to a unique id (many events can go to one id) and each event would have a data ...
I am not familiar with the pre-packaged solutions you mention. Were I to design this from scratch, I'd have a simple JS collecting info on clicks and posting it back to the server via Ajax (using whatever JS framework you're already using), and on the server side I'd simply append that info to a log file for later "of...
0.386912
false
2
671
2010-07-17 09:38:39.810
Populating a SQLite3 database from a .txt file with Python
I am trying to setup a website in django which allows the user to send queries to a database containing information about their representatives in the European Parliament. I have the data in a comma seperated .txt file with the following format: Parliament, Name, Country, Party_Group, National_Party, Position 7, Mart...
You asked what the create(**dict(zip(fields, row))) line did. I don't know how to reply directly to your comment, so I'll try to answer it here. zip takes multiple lists as args and returns a list of their correspond elements as tuples. zip(list1, list2) => [(list1[0], list2[0]), (list1[1], list2[1]), .... ] dict take...
0.135221
false
1
672
2010-07-19 19:24:12.837
python handle endless XML
I am working on a application, and my job just is to develop a sample Python interface for the application. The application can provide XML-based document, I can get the document via HTTP Get method, but the problem is the XML-based document is endless which means there will be no end element. I know that the document...
If the document is endless why not add end tag (of main element) manually before opening it in parser? I don't know Python but why not add </endtag> to string?
0
false
1
673
2010-07-20 11:30:10.800
Maximum level of recursion in Python
What's the maximum level of recursion and how do I change it in Python?
The default is 1000 levels deep and you can change that using the setrecursionlimit function in the sys module. Warning: Beware that some operating systems may start running into problems if you go much higher due to limited stack space.
1.2
true
1
674
2010-07-20 11:50:18.147
Web-ifing a python command line script?
This is my first questions here, so I hope it will be done correctly ;) I've been assigned the task to give a web interface to some "home made" python script. This script is used to check some web sites/applications availability, via curl commands. A very important aspect of this script is that it gives its results in ...
Your task sounds interesting. :-) A scenario that just came into mind: You continuosly scrape the resources with your home-brew scripts, and push the results into your persistent database and a caching system -- like Redis -- simultanously. Your caching system/layer serves as primary data source when serving client req...
0
false
1
675
2010-07-20 13:31:58.920
Blender, UV Layer, Image and Python
I'm trying to access UV Layer in Blender from Python and basically API returns UV Layer only as a string. Thing is I want to assign new Image object to current UV Layer ( I use TexFace on the side of material ) and then just bake lighting. All meshes are currently unwrapped, the only thing which is missing is an Image ...
What you could do is (if you are using Blender 2.49b) set the image of the Texture object and the uvlayer property of the MTex object.
0
false
1
676
2010-07-20 21:50:24.070
Browser-based MMO best-practice
I am developing an online browser game, based on google maps, with Django backend, and I am getting close to the point where I need to make a decision on how to implement the (backend) timed events - i.e. NPC possession quantity raising (e.g. city population should grow based on some variables - city size, application ...
Running a scheduled task to perform updates in your game, at any interval, will give you a spike of heavy database use. If your game logic relies on all of those database values to be up to date at the same time (which is very likely, if you're running an interval based update), you'll have to have scheduled downtime f...
1.2
true
1
677
2010-07-21 10:59:39.573
How can I learn more about Python’s internals?
I have been programming using Python for slightly more than half an year now and I am more interested in Python internals rather than using Python to develop applications. Currently I am working on porting a few libraries from Python2 to Python3. However, I have a rather abstract view on how to make port stuff over fro...
should I go for a top-down or a bottom-up approach? Both! Seriously.
0.067922
false
1
678
2010-07-21 14:59:43.853
How do I set a breakpoint in a module other than the one I am running in Python IDLE?
If I edit two modules, eggs and ham, and module eggs imports ham, how do I run module eggs such that IDLE stops at breakpoints set in ham? So far, I have only been able to get IDLE to recognize breakpoints set in the module actually being run, not those being imported.
start IDLE open eggs, open ham set desired breakpoints in both files go to IDLE's shell, select Debug=>Debugger go back to eggs and to run. You should stop at break points in each file. (It works, I just tested it.)
1.2
true
1
679
2010-07-22 14:05:33.280
how to get final redirected url
i am using google app engine for fetching the feed url bur few of the urls are 301 redirect i want to get the final url which returns me the result i am usign the universal feed reader for parsing the url is there any way or any function which can give me the final url.
You can do this by handling redirects manually. When calling fetch, pass in follow_redirects=False. If your response object's HTTP status is a redirect code, either 301 or 302, grab the Location response header and fetch again until the HTTP status is something else. Add a sanity check (perhaps 5 redirects max) to avoi...
0
false
2
680
2010-07-22 14:05:33.280
how to get final redirected url
i am using google app engine for fetching the feed url bur few of the urls are 301 redirect i want to get the final url which returns me the result i am usign the universal feed reader for parsing the url is there any way or any function which can give me the final url.
It is not possible to get the 'final' URL by parsing, in order to resolve it, you would need to at least perform an HTTP HEAD operation
0.386912
false
2
680
2010-07-22 18:13:57.290
django URL reverse: When URL reversig a username it fails when username has a '.' literal in it
I didn't expect this to occur [since I didn't know when django changed to allow _ and . in usernames], but when I attempt {% url feed_user entry.username %} I will get a 500 error when the username contains a '.' In this case rob.e as a username will fail. Any ideas how to deal with this?
The problem will be in whatever regex you are using in your urls.py to match feed_user. Presumably you are using something like r'(?P<username>\w+)/$', which only matches on alphanumeric characters and doesn't match on punctuation. Instead, use this: r'(?P<username>[\w.]+)/$'
1.2
true
1
681
2010-07-24 06:41:38.450
Maven equivalent for python
I'm a java developer/python beginner, and I'm missing my maven features, particularly dependency management and build automation (I mean you don't build, but how to create a package for deployment?) Is there a python equivalent to achieve these features? Note: I use python 2.x Thanks.
It's good to use virtualenv to create standalone project environment and use pip/easy_install to management dependencies.
0.454054
false
1
682
2010-07-24 15:12:56.707
What is the relation between PATH_MAX and NAME_MAX, and how do I obtain?
In limits.h, and in various places in the POSIX manpages, there are references to PATH_MAX and NAME_MAX. How do these relate to one another? Where is the official documentation for them? How can I obtain them at run time, and (where relevant) compile time for the C, Python, and GNU (shell) environments?
PATH_MAX is the maximum length of a filesystem path. NAME_MAX is the maximum length of a filename (in a particular spot). So, /foo/bar is restricted by PATH_MAX, and only the bar portion has its length limited by NAME_MAX. You can get these at run time via pathconf, as _PC_PATH_MAX and _PC_NAME_MAX, although standard...
1.2
true
1
683
2010-07-25 01:12:32.480
How to modify django cms multilingual middleware
hey guys, im trying to internationalize my site, so i have the django cms multilingual middleware class in my settings.py , when viewed from brasil, the url changes to www.ashtangayogavideo.com/pt/ash/homepage/ resulting in a 404, because my site is in www.ashtangayogavideo.com/ash/en/homepage, how can i configure the ...
Sounds like you need to modify your urls.py, not your settings or middleware.
0.673066
false
1
684
2010-07-25 02:49:30.333
Making a Toggle Button with an image in Tkinter
I know how to make an image a button in Tkinter, now how do I make th image a toggle button similar to a radio button?
Use a checkbutton with "indicatoron" set to False. This will turn off the little checkbox so you only see the image (or text), and the relief will toggle between raised and sunken each time it is clicked. Another way is to use a label widget and manage the button clicks yourself. Add a binding for <1> and change the r...
1.2
true
1
685
2010-07-25 06:03:24.040
Get the length in characters of a PyGTK TextView
I have a gtk TextView in a maximized window and I want to know how many characters a line can fit before you have to scroll.
(Friendly reminder, please stop putting answers in the comments, people.) To summarize: It depends on the size of the TextView, size of the window, size of the font, and as Alex Martelli said, the particular font and the usage of letters..."i" is a narrow letter, "m" is a wide letter, thus you can fit more "i"s than yo...
0
false
1
686
2010-07-26 04:48:52.253
Help : Realtime graphical interface in wxpython
I am new to this post as well as to python GUI programming.I want to make a realtime graphical GUI in wxpython.My requirement is that i have to catch signals from a device and i have to display the data in graphical as well as in textual form.The system should be accurate and be specific with the time constraints.Pleas...
If you can connect to this mysterious device and receive data from it from Python, then you can display said data with wxPython or any other GUI toolkit. You don't really say what kind of data it is or what you want to display? Lines? Graphs? Or what? If it's just tabular data, use the wx.ListCtrl (or ObjectListView) w...
0
false
1
687
2010-07-26 07:54:25.227
How can I upgrade the sqlite3 package in Python 2.6?
I was using Python 2.6.5 to build my application, which came with sqlite3 3.5.9. Apparently though, as I found out in another question of mine, foreign key support wasn't introduced in sqlite3 until version 3.6.19. However, Python 2.7 comes with sqlite3 3.6.21, so this work -- I decided I wanted to use foreign keys in ...
I decided I'd just give this a shot when I realized that every library I've ever installed in python 2.6 resided in my site-packages folder. I just... copied site-packages to my 2.7 installation, and it works so far. This is by far the easiest route for me if this works -- I'll look further into it but at least I can c...
0.135221
false
2
688
2010-07-26 07:54:25.227
How can I upgrade the sqlite3 package in Python 2.6?
I was using Python 2.6.5 to build my application, which came with sqlite3 3.5.9. Apparently though, as I found out in another question of mine, foreign key support wasn't introduced in sqlite3 until version 3.6.19. However, Python 2.7 comes with sqlite3 3.6.21, so this work -- I decided I wanted to use foreign keys in ...
download the latest version of sqlite3.dll from sqlite website and replace the the sqlite3.dll in the python dir.
0.673066
false
2
688
2010-07-26 16:21:34.060
Python/Web: What's the best way to run Python on a web server?
I am leasing a dedicated web server. I have a Python web-application. Which configuration option (CGI, FCGI, mod_python, Passenger, etc) would result in Python being served the fastest on my web server and how do I set it up that way? UPDATE: Note, I'm not using a Python framework such as Django or Pylons.
You don't usually just serve Python, you serve a specific web server or framework based on Python. eg. Zope, TurboGears, Django, Pylons, etc. Although they tend to be able to operate on different web server back-ends (and some provide an internal web server themselves), the best solution will depend on which one you us...
-0.067922
false
2
689
2010-07-26 16:21:34.060
Python/Web: What's the best way to run Python on a web server?
I am leasing a dedicated web server. I have a Python web-application. Which configuration option (CGI, FCGI, mod_python, Passenger, etc) would result in Python being served the fastest on my web server and how do I set it up that way? UPDATE: Note, I'm not using a Python framework such as Django or Pylons.
Don't get carried away with trying to work out what is the fastest web server. All you will do in doing that is waste your time. This is because the web server is nearly never the bottleneck if you set them up properly. The real bottleneck is your web application, database access etc. As such, choose whatever web hosti...
0.265586
false
2
689
2010-07-26 21:50:43.673
Dynamically update wxPython staticText
i was wondering how to update a StaticText dynamically in wxpython? I have a script that goes every five minutes and reads a status from a webpage, then prints using wxpython the status in a static input. How would i dynamically, every 5 minutes update the statictext to reflect the status? thanks alot -soule
Call the SetLabel method in your static text instance. So you don't run into conflict with the size, make sure your StaticText instance is created with enough space to write the future labels you'll want to write to it.
0.201295
false
1
690
2010-07-27 04:44:38.230
saving data and calling data python
say i want to ask the many users to give me their ID number and their name, than save it. and than i can call any ID and get the name. can someone tell me how i can do that by making a class and using the _ _ init _ _ method?
The "asking" part, as @Zonda's answer says, could use raw_input (or Python 3's input) at a terminal ("command window" in Windows); but it could also use a web application, or a GUI application -- you don't really tell us enough about where the users will be (on the same machine you're using to run your code, or at a br...
0.265586
false
1
691
2010-07-27 11:25:28.447
Does XML-RPC in general allows to call few functions at once?
Can I ask for few question in one post to XML-RPC server? If yes, how can I do it in python and xmlrpclib? I'm using XML-RPC server on slow connection, so I would like to call few functions at once, because each call costs me 700ms.
Whether or not possible support of multicall makes any difference to you depends on where the 700ms is going. How did you measure your 700ms? Run a packet capture of a query and analyse the results. It should be possible to infer roughly round-trip-time, bandwidth constraints, whether it's the application layer of the ...
0
false
1
692
2010-07-27 12:54:16.533
Starting a GUI process from a Python Windows Service
I am creating Windows service class in Python that will eventually display a Window when certain conditions are met. Since (as I understand it) services cannot have GUIs, I'm trying to start up a GUI in a seperate process (using subprocess.Popen) when the conditions are right. This isn't working, presumably because the...
If you give your Service the Allow service to interact with desktop permission it will be able to create windows without the need to launch a subprocess.
1.2
true
1
693
2010-07-27 16:32:21.153
Getting number of elements in an iterator in Python
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting?
Regarding your original question, the answer is still that there is no way in general to know the length of an iterator in Python. Given that you question is motivated by an application of the pysam library, I can give a more specific answer: I'm a contributer to PySAM and the definitive answer is that SAM/BAM files do...
0.170186
false
5
694
2010-07-27 16:32:21.153
Getting number of elements in an iterator in Python
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting?
This is against the very definition of an iterator, which is a pointer to an object, plus information about how to get to the next object. An iterator does not know how many more times it will be able to iterate until terminating. This could be infinite, so infinity might be your answer.
0
false
5
694
2010-07-27 16:32:21.153
Getting number of elements in an iterator in Python
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting?
It's common practice to put this type of information in the file header, and for pysam to give you access to this. I don't know the format, but have you checked the API? As others have said, you can't know the length from the iterator.
0
false
5
694
2010-07-27 16:32:21.153
Getting number of elements in an iterator in Python
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting?
There are two ways to get the length of "something" on a computer. The first way is to store a count - this requires anything that touches the file/data to modify it (or a class that only exposes interfaces -- but it boils down to the same thing). The other way is to iterate over it and count how big it is.
0.064358
false
5
694
2010-07-27 16:32:21.153
Getting number of elements in an iterator in Python
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting?
An iterator is just an object which has a pointer to the next object to be read by some kind of buffer or stream, it's like a LinkedList where you don't know how many things you have until you iterate through them. Iterators are meant to be efficient because all they do is tell you what is next by references instead of...
0.190967
false
5
694
2010-07-28 08:06:35.100
Getting started with Pylons and MVC - Need some guidance on design
I've been getting more and more interested in using Pylons as my Python web framework and I like the idea of MVC but, coming from a background of never using 'frameworks/design patterns/ what ever it\'s called', I don't really know how to approach it. From what I've read in the Pylons Book, so far, it seems I do the fo...
Model is for your db-related code. All queries go there, including adding new records/updating existing ones. Controllers are somewhat ambigous, different projects use different approaches to it. Reddit for example does fair bit of what should be View in controllers. I, for one, prefer to limit my controllers to reques...
0
false
1
695
2010-07-28 08:28:54.497
Debug C++ code in visual studio from python code running in eclipse
Does any one know how we can do this? I have python code in eclipse and whenever it calls c++ functions, i want the break point to go to the visual studio c++ project.
If the C++ app runs as a separate process then its pretty easy. You can run the process yourself or attach visual studio to existing running process and put break points. If C++ code is an embedded DLL/LIB then you can use python as debug/launch process. As soon as python will load the DLL/LIB into your python code v...
0.386912
false
1
696
2010-07-29 13:18:43.097
Scraping websites with Javascript enabled?
I'm trying to scrape and submit information to websites that heavily rely on Javascript to do most of its actions. The website won't even work when i disable Javascript in my browser. I've searched for some solutions on Google and SO and there was someone who suggested i should reverse engineer the Javascript, but i ha...
I would actually suggest using Selenium. Its mainly designed for testing Web-Applications from a "user perspective however it is basically a "FireFox" driver. I've actually used it for this purpose ... although I was scraping an dynamic AJAX webpage. As long as the Javascript form has a recognizable "Anchor Text" th...
0.386912
false
1
697
2010-07-29 13:47:31.353
E-mail traceback on errors in Bottle framework
I am using the Bottle framework. I have set the @error decorator so I am able to display my customized error page, and i can also send email if any 500 error occurs, but I need the complete traceback to be sent in the email. Does anyone know how to have the framework include that in the e-mail?
in the error500 function written after the @error decorator to serve my customized error page, wrote error.exception and error.traceback, these two give the exception and complete traceback of the error message.
0.545705
false
1
698
2010-07-30 00:37:59.267
Hide/Delete a StaticText in wxPython
I was wondering how to hide/delete a StaticText in wxPython?
Have you tried control.Hide() or control.Show(False)?
1.2
true
3
699
2010-07-30 00:37:59.267
Hide/Delete a StaticText in wxPython
I was wondering how to hide/delete a StaticText in wxPython?
statictext.Show to show and statictext.Hide to hide
0
false
3
699
2010-07-30 00:37:59.267
Hide/Delete a StaticText in wxPython
I was wondering how to hide/delete a StaticText in wxPython?
The widget's Hide/Show methods should work. If the widget is in a sizer, then you can use the sizer's Detach method to "hide" it but not destroy it. Otherwise, the sizer has a Remove method that will remove the widget and destroy it. And there's the widget's own Destroy method.
0.591696
false
3
699
2010-07-30 04:43:27.603
Zooming With Python Image Library
I'm writing a simple application in Python which displays images.I need to implement Zoom In and Zoom Out by scaling the image. I think the Image.transform method will be able to do this, but I'm not sure how to use it, since it's asking for an affine matrix or something like that :P Here's the quote from the docs: im...
You would be much better off using the EXTENT rather than the AFFINE method. You only need to calculate two things: what part of the input you want to see, and how large it should be. For example, if you want to see the whole image scaled down to half size (i.e. zooming out by 2), you'd pass the data (0, 0, im.size[0],...
1.2
true
1
700
2010-07-30 06:17:35.247
Running a .py file on LAMP (CentOS) server - from a PHP developer's perspective
I'm a LAMP developer trying out Python for the first time.. I'm okay with picking up the syntax, but I can't figure out how to run it on the server! I've tried the following uploading filename.py to a regular web/public directory. chmod 777, 711, 733, 773... (variations of execute) putting the filename.py in cgi-bin, ...
you can use cgi, but that will not have great performance as it starts a new process for each request. More efficient alternatives are to use fastcgi or wsgi A third option is to run a mini Python webserver and proxy the requests from apache using rewrite rules
0.135221
false
1
701
2010-07-30 12:10:06.963
Writing unit tests in Python: How do I start?
I completed my first proper project in Python and now my task is to write tests for it. Since this is the first time I did a project, this is the first time I would be writing tests for it. The question is, how do I start? I have absolutely no idea. Can anyone point me to some documentation/ tutorial/ link/ book that I...
nosetests is a brilliant solution for unit testing in Python. It supports both unittest based testcases and doctests, and gets you started with it with just a simple configuration file.
0.173164
false
1
702
2010-07-30 12:51:55.423
pyqt, webkit and facebook authentication?
Are there any examples how to authenticate your desktop Facebook application using PyQT and embedded webkit? This is to provide better user experience than opening Facebook authentication page in a separate browser window.
I don't believe you can open an "authentication page" in a separate window under Facebook's terms (I used to work for Zynga, and we couldn't then, so I don't know how you'd achieve this now legally). Second, you're looking into the QWebkit backwards I believe. From a UI perspective this is supposed to provide access t...
1.2
true
1
703
2010-07-31 02:08:42.593
Django object extension / one to one relationship issues
Howdy. I'm working on migrating an internal system to Django and have run into a few wrinkles. Intro Our current system (a billing system) tracks double-entry bookkeeping while allowing users to enter data as invoices, expenses, etc. Base Objects So I have two base objects/models: JournalEntry JournalEntryItems defin...
All fields in the superclass also exist on the subclass, so having an explicit relation is unnecessary. Model inheritance in Django is terrible. Don't use it. Python doesn't need it anyway.
0
false
2
704
2010-07-31 02:08:42.593
Django object extension / one to one relationship issues
Howdy. I'm working on migrating an internal system to Django and have run into a few wrinkles. Intro Our current system (a billing system) tracks double-entry bookkeeping while allowing users to enter data as invoices, expenses, etc. Base Objects So I have two base objects/models: JournalEntry JournalEntryItems defin...
First, inheriting from a model creates an automatic OneToOneField in the inherited model towards the parents so you don't need to add them. Remove them if you really want to use this form of model inheritance. If you only want to share the member of the model, you can use Meta inheritance which will create the inherit...
1.2
true
2
704
2010-07-31 08:52:01.250
how to change the color of a QGraphicsTextItem
i have a scene with a multiple (QGraphicsTextItem)s, and i need to have control over their colors , so how to change a color of a QGraphicsTextItem ? is it possible anyway? i've been trying for 3 days until now . please help thanks in advance
setDefaultTextColor(col) "Sets the color for unformatted text to col." The documentation is not clear about what "unformatted text" means. I think it means: "all portions of the contents of the item that have not been styled." The contents is a QTextDocument. You style a part of a document using a QTextCursor. You ca...
0.386912
false
1
705
2010-07-31 17:03:07.893
Deploying python app to Mac and Windows users
I've written an app in python that depends on wxPython and some other python libraries. I know about pyexe for making python scripts executable on Windows, but what would be the easiest way to share this with my Mac using friends who wouldn't know how to install the required dependencies? One option would be to bundle ...
How do people usually deploy such apps? 2 choices. With instructions. All bundled up. You write simple instructions like this. Folks can follow these pretty reliably, unless they don't have enough privileges. Sometimes they need to sudo in linux environments. Download easy_install (or pip) easy_install this, easy...
0
false
1
706
2010-08-01 06:20:07.297
Create Explorer.exe's File - Context Menu in WxPython application
I have a WxPython app that, among other things, has a integrated file-browser. I want to be able to create a system-default file context menu (e.g. what you get if you right-click on a file in windows explorer) when a user right clicks on one of the items within my application. Note: I already know how to create my own...
If you have python win32 installed, then look under the directory <PYTHON>/lib/site-packages/win32comext/shell/demos/servers. This contains a file context_menu.py which has sample code for creating a shell extension. Update: I think you want the folder_view.py sample.
0
false
1
707
2010-08-02 08:20:40.663
Using the ttk (tk 8.5) Notebook widget effectively (scrolling of tabs)
I'm working on a project using Tkinter and Python. In order to have native theming and to take advantage of the new widgets I'm using ttk in Python 2.6. My problem is how to allow the user to scroll through the tabs in the notebook widget (a la firefox). Plus, I need a part in the right edge of the tabs for a close but...
The notebook widget doesn't do scrolling of tabs (or multiple layers of them either) because the developer doesn't believe that they make for a good GUI. I can see his point; such GUIs tend to suck. The best workaround I've seen is to have a panel on the side that allows the selection of which pane to display. You can ...
1.2
true
2
708
2010-08-02 08:20:40.663
Using the ttk (tk 8.5) Notebook widget effectively (scrolling of tabs)
I'm working on a project using Tkinter and Python. In order to have native theming and to take advantage of the new widgets I'm using ttk in Python 2.6. My problem is how to allow the user to scroll through the tabs in the notebook widget (a la firefox). Plus, I need a part in the right edge of the tabs for a close but...
I've never used these widgets so I have no idea how possible this is, but what I would try is something akin to the grid_remove() method. If you can move the tabs to an invisible widget, or just make them invisible without losing content, that's what I'd look for/try.
0
false
2
708
2010-08-02 14:53:11.530
How to get the IPv6 address of an interface under linux
Do you know how I could get one of the IPv6 adress of one of my interface in python2.6. I tried something with the socket module which lead me nowhere. Thanks.
You could just simply run 'ifconfig' with a subprocess.* call and parse the output.
0
false
1
709
2010-08-02 20:40:07.427
Need to create thumbnail, how to ensure proportions and set fixed width?
I want to create a thumbnail, and the width has to be either fixed or no bigger than 200 pixels wide (the length can be anything). The images are either .jpg or .png or .gif I am using python. The reason it has to be fixed is so that it fits inside a html table cell.
Look at PyMagick, the python interface for the ImageMagick libraries. It's fairly simple to resize an image, retaining proportion, while limiting the longest side. edit: when I say fairly simple, I mean you can describe your resize in terms of the longest acceptable values for each side, and ImageMagick will preserve ...
0.386912
false
1
710
2010-08-02 20:58:39.440
PyObjC giving strange error - [OC_PythonUnicode representations]: unrecognized selector sent to instance 0x258ae2a0
I have this line: NSWorkspace.sharedWorkspace().setIcon_forFile_options_(unicode(icon),unicode(target),0) Why does it give that error and how do I fix it? Thank you.
I misread the documentation. I need to do this: NSWorkspace.sharedWorkspace().setIcon_forFile_options_(NSImage.alloc().initWithContentsOfFile_(icon),target,0) Unfortunately the error is what confused me.
1.2
true
1
711
2010-08-02 22:34:46.590
Disconnecting from host with Python Fabric when using the API
The website says: Closing connections: Fabric’s connection cache never closes connections itself – it leaves this up to whatever is using it. The fab tool does this bookkeeping for you: it iterates over all open connections and closes them just before it exits (regardless of whether the tasks failed or...
If you don't want to have to iterate through all open connections, fabric.network.disconnect_all() is what you're looking for. The docstring reads """ Disconnect from all currently connected servers. Used at the end of fab's main loop, and also intended for use by library users. """
1.2
true
1
712
2010-08-03 02:57:20.570
Prevent A User From Downloading Files from Python?
I am working on a project that requires password protected downloading, but I'm not exactly sure how to implement that. If the target file has a specific extension (.exe, .mp3, .mp4, etc), I want to prompt the user for a username and password. Any ideas on this? I am using Python 26 on Windows XP.
This is best implemented at the web server level. If you are using Apache, this can be done by placing the files you desire to protect in a directory with an htaccess file which requires user authentication. Then, implement HTTP Basic Auth in your Python script to download the files. Make sure to use an SSL connection...
0.386912
false
1
713
2010-08-03 14:38:50.270
In Django, how to get django-storages, boto and easy_thumbnail to work nicely?
I'm making a website where files are uploaded through the admin and this will then store them on Amazon S3. I'm using django-storages and boto for this, and it seems to be working just fine. Thing is, I'm used to use my easy_thumbnails (the new sorl.thumbnail) on the template side to create thumbnails on the fly. I pre...
easy_thumbnails will do S3-based image thumbnailing for you - you just need to set settings.THUMBNAIL_DEFAULT_STORAGE, so that easy_thumbnails knows which storage to use (in your case, you probably want to set it to the same storage you're using for your ImageFields).
1
false
1
714
2010-08-03 15:05:07.733
how can i verify all links on a page as a black-box tester
I'm tryng to verify if all my page links are valid, and also something similar to me if all the pages have a specified link like contact. i use python unit testing and selenium IDE to record actions that need to be tested. So my question is can i verify the links in a loop or i need to try every link on my own? i trie...
What exactly is "Testing links"? If it means they lead to non-4xx URIs, I'm afraid You must visit them. As for existence of given links (like "Contact"), You may look for them using xpath.
0
false
2
715
2010-08-03 15:05:07.733
how can i verify all links on a page as a black-box tester
I'm tryng to verify if all my page links are valid, and also something similar to me if all the pages have a specified link like contact. i use python unit testing and selenium IDE to record actions that need to be tested. So my question is can i verify the links in a loop or i need to try every link on my own? i trie...
You could (as yet another alternative), use BeautifulSoup to parse the links on your page and try to retrieve them via urllib2.
0
false
2
715
2010-08-03 20:08:34.123
Calling a python script from command line without typing "python" first
Question: In command line, how do I call a python script without having to type python in front of the script's name? Is this even possible? Info: I wrote a handy script for accessing sqlite databases from command line, but I kind of don't like having to type "python SQLsap args" and would rather just type "SQLsap arg...
You want a shebang. #!/path/to/python. Put that on the first line of your python script. The #! is actually a magic number that tells the operating system to interpret the file as a script for the program named. You can supply /usr/bin/python or, to be more portable, /usr/bin/env python which calls the /usr/bin/env pro...
0.327599
false
2
716
2010-08-03 20:08:34.123
Calling a python script from command line without typing "python" first
Question: In command line, how do I call a python script without having to type python in front of the script's name? Is this even possible? Info: I wrote a handy script for accessing sqlite databases from command line, but I kind of don't like having to type "python SQLsap args" and would rather just type "SQLsap arg...
Assuming this is on a unix system, you can add a "shebang" on the top of the file like this: #!/usr/bin/env python And then set the executable flag like this: chmod +x SQLsap
0.265586
false
2
716
2010-08-04 04:31:07.850
Find max length word from arbitrary letters
I have 10 arbitrary letters and need to check the max length match from words file I started to learn RE just some time ago, and can't seem to find suitable pattern first idea that came was using set: [10 chars] but it also repeats included chars and I don't know how to avoid that I stared to learn Python recently b...
I assume you are trying to find out what is the longest word that can be made from your 10 arbitrary letters. You can keep your 10 arbitrary letters in a dict along with the frequency they occur. e.g., your 4 (using 4 instead of 10 for simplicity) arbitrary letters are: e, w, l, l. This would be in a dict as: {'e':1,...
0
false
1
717