So this Python problem has been giving me problems since I've tried refactoring the code into different files. I have a file called object.py and in it, the related code is:
class Object:
#this is a generic object: the player, a monster, an item, the stairs...
#it's always represented by a character on screen.
def __init__(self, x, y, ...
I have a very large (~8 gb) text file that has very long lines. I would like to pull out lines in selected ranges of this file and put them in another text file. In fact my question is very similar to this and this but I keep getting stuck when I try to select a range of lines instead of a single line.
So far this is the only approa...
I used to think that once a module was loaded, no re-importing would be done if other files imported that same module, or if it were imported in different ways. For example, I have mdir/__init__.py, which is empty, and mdir/mymod.py, which is:
thenum = None
def setNum(n):
global thenum
if thenum is not None:
raise ValueE...
i need to make a dictionary in javascript like this
i dont remember the exact notation, but it was something like:
states_dictionary={ CT=[alex,harry], AK=[liza,alex], TX=[fred, harry] ........ }
is there such a thing in javascript?
...
I was reading another question on SO (zen of python), and I came across this line in Jaime Soriano's answer:
import this
"".join([c in this.d and this.d[c] or c for c in this.s])
Entering the above in a python shell prints:
"The Zen of Python, by Tim Peters\n\nBeautiful is better than ugly.\nExplicit is
better than implicit.\nSimple ...
I've got a webserver that I'm presently benchmarking for CPU usage. What I'm doing is essentially running one process to slam the server with requests, then running the following bash script to determine the CPU usage:
#! /bin/bash
for (( ;; ))
do
echo "`python -c 'import time; print time.time()'`, `ps -p $1 -o '%cpu' | grep -vi ...
How to generate a random (but unique and sorted) list of a fixed given length out of numbers of a given range in python?
Something like that:
>>>> list_length = 4
>>>> values_range = [1,30]
>>>> random_list(list_length,values_range)
[1,6,17,29]
>>>> random_list(list_length,values_range)
[5,6,22,24]
>>>> random_list(3,[0,11])
[0,7,...
I'm just starting to work on a tornado application that is having some CPU issues. The CPU time will monotonically grow as time goes by, maxing out the CPU at 100%. The system is currently designed to not block the main thread. If it needs to do something that blocks and asynchronous drivers aren't available, it will spawn another thr...
I am trying to have my script be able to take in an arbitrary number of file names as command line arguments. In Unix, it is possible to use the '*' key to represent any character. For example,
ls blah*.txt
will list every file with blah at the beginning and txt at the end.
I need something like this for my python script.
python...
Is it possible to calculate the number e with high precision (2000+ decimal places) with Python? (I was thinking with Numpy or SciPy)
...
This is for a friend and we are brand new to Python.
There is a string, for example EXAMPLE
How can I remove the middle character i.e. M from it. I don't need the code, what I want to know is
Do strings in python end in any special character?
Which is a better way - shifting everything right to left starting from the middle character...
Hello:
One script is used to exchange file information amongst teams. It is used as:
$ share.py -p /path/to/file.txt
The argument checking ensures that /path/to/file.txt exists and has the correct permissions:
#[...]
# ensure that file exists and is readable
if not os.access(options.path, os.F_OK):
raise MyError('the file does not ...
I'm writing a Tkinter GUI in Python. It has an Entry for searching with a results ListBox below it. The ListBox also has a Scrollbar. How can I get scrolling with the mouse and arrow keys to work in the ListBox without switching focus away from the search field? IE I want the user to be able to type a search, scroll around, and keep typi...
How can I modify the list below:
[('AAA', '1-1', 1, (1.11, (2.22, 3.33))), ('BBB', '2-2', 2, (4.44, (5.55, 6.66))), ('CCC', '3-3', 3, (7, (8, 9)))]
into something like this:
[('AAA', '1-1', 1, 1.11, 2.22, 3.33), ('BBB', '2-2', 2, 4.44, 5.55, 6.66), ('CCC', '3-3', 3, 7, 8, 9)]
Many thanks in advance.
...
basically I have a bunch of files containing domains. I've sorted each individual file based on its TLD using .sort(key=func_that_returns_tld)
now that I've done that I want to merge all the files and end up wtih one massive sorted file. I assume I need something like this:
open all files
read one line from each file into a list
sort l...
Latest django mailer from trunk http://github.com/jtauber/django-mailer/tree/master/docs/
Tested with Postgresql 8.4, sqlite3
template
{{ title }}
forms.py
#-*- coding: utf-8 -*-
if "mailer" in settings.INSTALLED_APPS:
from mailer import send_mail
else:
from django.core.mail import send_mail
...
body_txt = render...
Hi all! I have the following problem. I have a list of different text lines that all has a comma in it. I want to keep the text to the left of the comma and delete everything that occurs after the comma for all the lines in the file.
Here is a sample line from the file:
1780375 "004956 , down , 943794 , 22634 , ET , 2115 ,
I'd like ...
I am using Python 2.6 and I have two data stores. Querying the first one returns a list of document IDs in a specific order. I look up all the documents at once in the second data store using these IDs, which returns a list of dictionaries (one for each doc), but not in the same order as the original list. I now need to re-sort this list...
Hi,
I want to be able to use the PIL library on a web hosting machine. The machine has Python 2.4.3 installed, but not the PIL library. I tried downloading the PIL source and putting the PIL folder into my directory. It kind of works, except when I need to do some actual image processing, which brings up an ImportError, saying that "The...
In Python I can write:
for i, val in enumerate(lst):
print i, val
The only way I know how to do this in PHP is:
for($i = 0; $i < count(lst); $i++){
echo "$i $val\n";
}
Is there a cleaner way in PHP?
...