How can I have URLs like example.com/category/catename-operation/ in Django?
Also in some cases the user enters a space separated category, how can I handle that?
E.g if the user enters the category as "my home", then the URL for this category will become
example.com/my home/ which is not a valid URL.
How can I handle these things?
...
If I have a list in python, how can I create a reference to part of the list? For example:
myList = ["*", "*", "*", "*", "*", "*", "*", "*", "*"]
listPart = myList[0:7:3] #This makes a new list, which is not what I want
myList[0] = "1"
listPart[0]
"1"
Is this possible and if so how would I code it?
Cheers,
Joe
...
[(',', 52),
('news', 15),
('.', 11),
('bbc', 8),
('and', 8),
('the', 8),
(':', 6),
('music', 5),
('-', 5),
('blog', 4),
('world', 4),
('asia', 4),
('international', 4),
('on', 4),
('itunes', 4),
('online', 4),
('digital', 3)]
Suppose I have this list, with tuples inside.
How do I go through the list and remove elemen...
I came across the folloqing type of code when looking for some pyQt examples :
class DisplayPage(QWizardPage):
def __init__(self, *args):
apply(QWizardPage.__init__, (self, ) + args)
What does *args mean ?
What is the purpose of using apply for this type of code ?
...
This is a question:
"Where is the car?"
This is NOT a question:
"Check this out: http://domain.com/?q=test"
How do I write a function to analyze a string so that we know for sure it is a question and not part of a URL?
...
Hi so,
I've been having a lot of problems with emacs and trying to get the terminal to work with:
M-x term
I installed cygwin and I fixed up my .emacs to include the paths:
(setenv "PATH" (concat "c:/cygwin/bin;" (getenv "PATH")))
(setq exec-path (cons "c:/cygwin/bin" exec-path))
(require 'cygwin-mount)
(cygwin-mo...
Is there some way to just get the next token from a file in Python, as for example the Scanner class does in Java?
File file = new File("something");
Scanner in = new Scanner(file);
double a = in.nextDouble();
String s = in.next();
I'd like to ignore whitespaces, tabs, newlines and just get the next int/float/word from the file. I kno...
I would like to know if it's possible to use django over existing db tables that defines the models.
Instead of defining models in order to create db tables
...
I need to cluster some text documents and have been researching various options. It looks like LingPipe can cluster plain text without prior conversion (to vector space etc), but it's the only tool I've seen that explicitly claims to work on strings.
Are there any Python tools that can cluster text directly? If not, what's the best wa...
Hello,
I have a server on which I have two sites built with Django and Python, one site is major site is build with an older version of django, the other with the newer release, I have upgraded to the new release and major aspects of my other site have broken, is it possible to tell the site to use a different version in say the pytho...
How to parse *.py file with python?
If my question is duplicated, please let me know another thread, because I can't find it.
Why I like to do is, I like to try Basic Source Code Converter from Python to Go Language.
Which module should I use?
And your Idea on, should I go ahead or better not?
If I should go ahead, please let me know...
Is there anyway i can know how much bytes taken by particular variable in python. E.g; lets say i have
int = 12
print (type(int))
it will print
<class 'int'>
But i wanted to know how many bytes it has taken on memory? is it possible?
...
How can I change the default behavior in the markdown filter so that it transforms a newline to a br tag?
...
With my Java projects at present, I have full version control by declaring it as a Maven project. However I now have a Python project that I'm about to tag 0.2.0 which has no version control. Therefore should I come accross this code at a later date, I won't no what version it is.
How do I add version control to a Python project, in th...
I have a list of booleans in python. I want to AND (or OR or NOT) them and get the result. The following code works but is not very pythonic.
def apply_and(alist):
if len(alist) > 1:
return alist[0] and apply_and(alist[1:])
else:
return alist[0]
Any suggestions on how to make it more pythonic appreciated.
...
Is there a pythonic way to build up a list that contains a running average of some function?
After reading a fun little piece about Martians, black boxes, and the Cauchy distribution, I thought it would be fun to calculate a running average of the Cauchy distribution myself:
import math
import random
def cauchy(location, scale):
...
I am trying to retrieve date from an email. At first it's easy:
message = email.parser.Parser().parse(file)
date = message['Date']
print date
and I receive:
'Mon, 16 Nov 2009 13:32:02 +0100'
But I need a nice datetime object, so I use:
datetime.strptime('Mon, 16 Nov 2009 13:32:02 +0100', '%a, %d %b %Y %H:%M:%S %Z')
which raise V...
I want to have compact class based python DSLs in the following form:
class MyClass(Static):
z = 3
def _init_(cls, x=0):
cls._x = x
def set_x(cls, x):
cls._x = x
def print_x_plus_z(cls):
print cls._x + cls.z
@property
def x(cls):
return cls._x
class MyOtherClass(MyClass):
z...
I have been given a file that I would like to extract the useful data from. The format of the file goes something like this:
LINE: 1
TOKENKIND: somedata
TOKENKIND: somedata
LINE: 2
TOKENKIND: somedata
LINE: 3
etc...
What I would like to do is remove LINE: and the line number as well as TOKENKIND: so I am just left with a string that ...
I need to generate a HTML using a Genshi template. The Html is, basicaly a very long html with tables. The data comes in a simple CSV, so, i read it with python, i put it into a list[] and then i call the template and send the variable (the list)
Actually i solved it by doing something like this in the template:
<html>
<?python>
fo...