I want to reduce the number of patterns I have to write by using a regex that picks up any or all of the pattern when it appears in a string.
Is this possible with Regex?
E.g. Pattern is: "the cat sat on the mat"
I would like pattern to match on following strings:
"the"
"the cat"
"the cat sat"
...
"the cat sat on the mat"
But it sho...
I have plans to create a simple bot for a game I run and have it sit on MSN and answer queries. I want to use Python to do this and googled around and found MSNP. I thought "great" and "how awesome" but it appears that it's about 5 years old and oddly enough doesn't connect to MSN as they've probably changed one or two small little thing...
I just configured Eclipse with PyDev latest version, but when I import external modules, neither code completion nor syntax highlighting works. How do I enable it?
Komodo Edit does a better synax highlighting, apparently. - But Ctrl+R doesnt run the program.
I prefer a SciTE kind of editor with similar highlighting and fonts (aestheti...
I have the following code in .py file:
import re
regex = re.compile(
r"""ULLAT:\ (?P<ullat>-?[\d.]+).*?
ULLON:\ (?P<ullon>-?[\d.]+).*?
LRLAT:\ (?P<lrlat>-?[\d.]+)""", re.DOTALL|re.VERBOSE)
I have the data in .txt file as a sequence:
QUADNAME: rockport_colony_SD
RESOLUTION: 10 ULLAT: 43.625 ULLON:
-97.87527466 LRLAT: 43.5...
I want to have some work done on the Network front, pinging numerous computers on a LAN and retrieving data about the response time. Which would be the most useful and productive to work with: Perl or Python?
...
I've read mixed reviews of both Suds and ZSI -- two Python SOAP libraries. However, I'm unclear whether either of them can support WS-Attachments. I'd prefer to use Suds (appears to be more straightforward), but I'll defer to whichever library suits my needs.
...
I've got a package set up like so:
packagename/
__init__.py
numbers.py
tools.py
...other stuff
Now inside tools.py, I'm trying to import the standard library module fractions. However, the fractions module itself imports the numbers module, which is supposed to be the one in the standard library.
The problem is that i...
if i do :
string = raw_input('Enter the value')
it will come on shell.
Can i collect the value I entered in variable string ???
How to use that entered value in my program like :
if dict.has_key('string'):
print dict[string]
???
...
I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).
# the string, which has an a-acute in it.
ss = u'Capit\xe1n'
ss8 = ss.encode('utf8')
repr(ss), repr(ss8)
("u'Capit\xe1n'", "'Capit\xc3\xa1n'")
print ss, ss8
print >> open('f1','w'), ss8
>>> file('f1').read()
'Capit\xc3\xa1n\n'
...
Here is the situation: I have a parent model say BlogPost. It has many Comments. What I want is the list of BlogPosts ordered by the creation date of its' Comments. I.e. the blog post which has the most newest comment should be on top of the list. Is this possible with SQLAlchemy?
...
Some C libraries export function pointers such that the user of the library sets that function pointer to the address of their own function to implement a hook or callback.
In this example library liblibrary.so, how do I set library_hook to a Python function using ctypes?
library.h:
typedef int exported_function_t(char**, int);
extern...
When I compile the code below, I get
IndentationError: unindent does not match any outer indentation level
import sys
def Factorial(n): # return factorial
result = 0
for i in range (1,n):
result = result * i
print "factorial is ",result
return result
Any ideas why?
...
I have this list
["[email protected] : martin00", ""],
How do i split so it only be left
[email protected]:martin00
...
When piping the output of a python program, the python interpreter gets confused about encoding and sets it to None. This means a program like this:
# -*- coding: utf-8 -*-
print "åäö"
will work fine when run normally, but fail with:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 0: ordinal not in range(...
I'm calling a function in Python which I know may stall and force me to restart the script. How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else.
Thanks
...
I want to reverse a regular expression. i.e. given a regular expression, I want to produce any string that will match that regex.
I know how to do this from a theoretical computer science background using finite state machine, I just want to know if someone has already written a library to do this. :)
I'm using Python, so I'd like a py...
i have:
for i in range(2,n):
if(something):
do something
else:
do something else
i = 2 **restart the loop
But that doesn't seem to work. Is there a way to restart that loop?
Thanks
...
I am a newbie to Python and have come across the following example in my book that is not explained very well. Here is my print out from the interpreter:
>>> s = 'spam'
>>> s[:-1]
'spa'
Why does slicing with no beginning bound and a '-1' return every element except the last one? Is calling s[0:-1] logically the same as calling s[:-1]?...
I need to convert 'one' into '1' 'two' into '2' and so on.
Is there a way to do this a library or a class or anything?
...
Given a situation in Django 1.0 where you have extra data on a Many-to-Many relationship:
class Player(models.Model):
name = models.CharField(max_length=80)
class Team(models.Model):
name = models.CharField(max_length=40)
players = models.ManyToManyField(Player, through='TeamPlayer', related_name='teams')
class TeamPlayer(models...