Hi, I am very bad with regexes.
I need a regular expression that will reduce a url like this:
hxxp://example.com/somefolder/something/whatever
to its base:
hxxp://example.com
The two slashes after the http: complicate things. I know I could just remove the "http://" and add it again later, but as a learning experience, I would like to do this regex in a single line....
User Profile
Collapse
-
quick regex question
-
If I followed your example, I would have to do this:
Code:def write(self, path, fn): for arg in self.args: arg.write('/'.join([path, fn]))
Here is basically how I ended up doing this:
Code:class Parent(object): def __init__(self): pass def foo(self, arg1, arg2): print
-
Alright, now I've just dug myself into a deeper hole.
What I'm basically trying to do is this:
I have a base class, called FileSystem. I then have two derived classes called DiskFileSystem and VirtualFileSyst em. Being derived classes, they have common methods like write(), read(), etc.
Say I want to write the same contents to the same file in a VirtualFileSyst em object and a DiskFileSystem object. Instead...Leave a comment:
-
Is there any way to get the arguments that were passed, too?
Something like this:
Code:def __getattr__(name, *args): # whatever
Leave a comment:
-
"Magic method" in python
Is there any way to do this in python? Basically, a default action that an object performs when a nonexistent method or member is accessed.
Edit: Nevermind, I found __getattr__(). Feel free to delete. -
OK, that works. I don't know what's happening with hoststr, though...the only two times that it's used in the program are the ones shown in the code. Whatever, it works though. Thanks.
EDIT: On a side note, if I replace the code in dnsLookup() so it looks like this:
Code:char * dnsLookup(char * hoststr, unsigned int proto) { return "testing"; }
Leave a comment:
-
Cannot pass char * array
EDIT: Title is a misnomer, it's not an array it's a pointer
I have a struct that I use to pass arguments to a function referenced by pthread_create( ). It looks like this:
Code:struct __tryConnect_args { int sock; char * hoststr; unsigned int port; int proto; };
-
That isn't right. AI_PASSIVE is for use with bind() and listen(), not connect()
iSeries Information Center
Edit: My code was correct. My firewall was configured to not accept connections from localhost. I don't know what's up with the irrelevant error messages, but the problem is now fixed. Thanks for the help anyway...Leave a comment:
-
C socket woes
I am having trouble using connect() when entering struct addrinfo members as parameters.
Code:int tcpConnect() { struct addrinfo hints; struct addrinfo *ai = NULL; int res; int sock1; char * ipaddr = "127.0.0.1"; char * port = "80"; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET;
-
C Protocol-Independent Sockets
I am learning the C interface to protocol-independent sockets, and I'm very confused. For example I keep reading in tutorials to not use sockaddr_in and sockaddr_in6 (since these are protocol-dependent structures), but I *need* to use them in order to use getaddrinfo(). So to start out: below is a function for a host name lookup. Is there any practical way to do this without using the nasty switch statements and the protocol-dependent structures?... -
-
-
I get this compile error
error: request for member ‘push_back’ in ‘vecptr’, which is of non-class type ‘std::vector'
Note that "vector" is the type passed to the function, in a different part of the code.
Edit: The function call looks like this:
Code:fileToContainer<vector<string> >(argv[1], &ph.puzGrid);
Leave a comment:
-
Using late-binding with STL classes
I have a function, which reads input from a file and appends each line of the file to an STL object. I want to use this function with both lists and vectors. Since both of these objects have the push_back method, I thought I'd make a common function that can be used by both. Is there any practical way to do this?
Function show below:
Code:template<class container> // The second argument here must be
-
Alias for STL object
I'm designing a program that frequently deals with coordinate pairs. I've decided to use stl::pair for this purpose. As these are all coordinate pairs, they will all be of type pair<int, int>. My question is, rather than declaring pair<int, int> each time, like seen here:
Code:pair<int, int> foo; void bar(pair<int, int>* biz) { return; }
-
OK thanks. And about the second part of my question...is there any logical reason for python to do this? Isn't it inconsistent for the assignment operator to assign a value to some data types and a reference to others? Just wondering why they did this.Leave a comment:
-
No, if you don't yet know how to code, Django is a horrible idea. Go through the tutorial, write some demo apps, and make sure that you feel comfortable with the language. Then write some CGI scripts (like a login form, comment box, etc.) so you know how cookies, post data, sessions, etc. work. *Then* take a look at Django.Leave a comment:
-
Copy a list
Consider the following code:
Code:listA = [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'], ['i', 'j', 'k', 'l']] changeCoordinates = ((2, 3), (1, 3)) for coordinateList in changeCoordinates: listB = listA[:] x = coordinateList[0] y = coordinateList[1] listB[x][y] = 'foo' print "list A: %s" % listA print "list B: %s" % listB
-
-
No activity results to display
Show More
Leave a comment: