No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
33 Posted Topics
How do I get datalist to string? >>> days = 24/6 >>> print days 4 >>> hours = 45/7 >>> print hours 6 >>> datalist = [] >>> datalist.append(days) >>> datalist.append(" days ") >>> print datalist [4, ' days '] >>> datalist_str = "".join(datalist) Traceback (most recent call last): File … | |
I have a file pointer which was assigned in main. In the main, I just open a file to write stuff to it. I want to pass the file pointer to several functions so that they can write to the file. In the fucntion declaration I just add: somefunc(FILE *file) … | |
When I execute the following sql,select id from people, inside python and print the result, I get this: ((11L,), (12L,), (13L,), (14L,), (15L,), (16L,), (17L,), (18L,), (19L,), (20L,)) Why does python print L beside the numbers. Just to indicate Long type? | |
I am looking for a good C++ example of a simple MySQL client program written in C++ and runs on Linux, using MySQL++ libraries that does the following (no threading): Accessing Option File Contents, ~/.my.cnf, in user home folder to read settings (load_defaults). Constructing and sending the sql statement that … | |
Line by line I need to get the whole content in a line from a file. I have looked at fgetc, fgets. According to fgets, I need to specify max number of characters to read. If I have file content like this: 1235690,9087657788888770000,89977553223456789\n I wouldn't know how max characters in … | |
[code=python] data = unpack('>L', sock.recv(4)) [/code] Does this line of code means, incoming data is big endian and so unpack to endianess of local machine and assign to data. If local machine is little endian, then big endian is automatically converted to little endian format? | |
I would like to convert url into md5 hash. My question is that md5 hash will create collision at 2^64. If you do long(value,16), where value is the md5 hash string, would value returned from long(value, 16) be unique as long as md5 hashed string is unique? when you move … | |
I have a CProgramA that need to call CProgramB just before CProgramA terminates. How can this be achieved? | |
strcpy(buf, "my_id_%d_",i) strcpy(buf1, "my_com_id_%d", j) First I want to place value of i into "my_id_1" like so and copy to buf. And do the same thing in second line the code. Now I want to join both buf and buf1 so it will give me a new string "my_id_1_my_com_id_2". How … | |
I am getting an error when I do this in C program: execl("/bin/cp","../data/data_.txt","../data/data.txt",0); error is as follows: ../data/data_.txt: missing destination file operand after `../data/data.txt' Try `../data/data_.txt --help' for more information. I tried this too, it didn't help. execl("/bin/cp ../data/data_.txt ../data/data.txt",0); All I am trying to do is this: cp ../data/data_.txt … | |
int file file = open("./some.txt", O_RDONLY); Above line file=open giving me compile error: 'O_RDONLY' undeclared (first use in this function) What is the problem here? I am running linux and gcc 4.1. | |
I have a config file which includes how many files I need to create. So my program reads the config file and will create those files. Where I am stuck is I do not know before hand how many File pointers I need. I get to know quantity of files … | |
When you read file in C and move to next line and so on. This seems you have to access file top to bottom sequentially without skipping lines. I need a way to read very 5th line or something similar to it. I am just concerned with data that is … | |
[QUOTE]aptr = malloc(nrows * ncols * sizeof(int)); rowptr = malloc(nrows * sizeof(int *));[/QUOTE] What is the different with have no * inside sizeof(), eg sizeof(int), vs sizeof(int *)? | |
char stmt_buf[1024], buf[(1024*2)+1]; stmt_buf ="SELECT id, title FROM post LIMIT 5;"; I get an error: connect2.c: In function ‘main’: connect2.c:217: error: incompatible types in assignment | |
I am running linux. This problem maybe implemented many times over. I am not hitting right google search term. I need a way to send email from my c program, if that program fails to excute some other part of the code. Any gurus like to shed some light on … | |
I have a C program I am writing and need this program to write to syslog and have the logs in a separate file for my program. Eg. My program is called "example.c", then I want to have a log file called "example.log" in /var/log. Do I define log file … | |
[QUOTE]The function time() retrieves the current calendar time from the system's clock. It has the following prototype: time_t time(time_t * tp); In systems in which no clock is available, the function returns -1.[/QUOTE] Part 1: I found this on the internet. I have a question about the above quote where … | |
Can someone tell me what value would each of the line of code will have, when you go through this code: Here is the full code: server.conf: [CODE]interface=192.168.0.2; log=/var/log/example; [/CODE] example.c: [CODE=c] conf_fd=open("/etc/example/server.conf",O_RDONLY); read(conf_fd,conf,100); close(conf_fd); /* Get server IP */ buffer=strtok(conf,";"); buffer1=strtok(NULL,";"); strtok(buffer,"="); server=strtok(NULL,"="); server_ip=inet_addr(server);[/CODE] What is the value at … | |
I am looking at the code which has the following: read(conf_fd,conf,100); Can someone tell me what these parameters are passed to read function? | |
I need to create a program and have it create a lock file so that only one instance of the program can be run at any one time. I came across this code: [CODE=c] for (tries = 0; tries != maxtries; ++tries) { fd = open("/tmp/some.lock.file", O_WRONLY|O_CREAT|O_EXCL, 0644); if (fd … | |
How do you compare two decimal numbers in python? | |
What and when you would use Decimal vs Float Type? | |
Why can't you do this? [code=python] a = [] a.append('1').append('2') [/code] You can only do this: [code=python] a.append('1') a.append('2') [/code] | |
I am looking at this recipe: [url]http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440509[/url] When I tried to do it, doesn't work. why? [CODE]>>> from sets import Set >>> new_list = [2,34,5,5,6,6,7,2] >>> print new_list [2, 34, 5, 5, 6, 6, 7, 2] >>> new_list = Set(new_list).elems Traceback (most recent call last): File "<interactive input>", line 1, … | |
what is %r mean? [code=python] "%r tag requires exactly two arguments" % token.contents.split()[0] [/code] | |
Can someone tell me what is the different between default_age and self.default_age? Only one default_age variable is created for all instance of class Student and self.default_age means very instances of class Student gets a variable default_age? How do you specify a static class(singleton class) in python? [code=python] class Student: default_age … | |
Why can't I have two different link objects? I create _link and _link2 as empty objects. When I do this: _link2 = _link, it just creates alias _link2 to link object. Same object have 2 aliases _link2 and _link. Is there a way to copy the content of _link to … | |
[code=python] s1 ='999' s2 = '99.99' mypat = re.compile('(^([0-9]+[.]+[0-9]+)|([0-9])$)') rate= mypat.search(s1) print rate.group() >>> print rate.groups() ('9', None, '9') >>> rate=mypat.search(s2) >>> print rate.group() 99.99 [/code] I need to get price = float(rate.group()). Price=999 or Price=99.99. I think there is a problem when s1='999', when I do this: [code=python] >>> … | |
Why you specify type and name of the exception in your custom exceptions, but not in python built in exceptions? except IOError: print "no file by the name ccy_rates*.txt" except MyError, e: print e.msg | |
I am trying to use BeautifulSoup: soup = BeautifulSoup(page) td_tags = soup.findAll('td') i=0 for td in td_tags: i = i+1 print "td: ", td # re.search('[0-9]*\.[0-9]*', td) price = re.compile('[0-9]*\.[0-9]*').search(td) I am getting an error: price= re.compile('[0-9]*\.[0-9]*').search(td) TypeError: expected string or buffer | |
test = [random.randint(1,10) for i in range(20)] Can someone what does the random.randint(1,10) fron to for loop does, and the square brackets around it means, make it a list? | |
I need to create python script that is threaded. So the main program will run in infinite loop and just retrieving messages and putting them in a queue. (Main thread) I need child threads from a pool to process the queue. When there is no stuff in the queue, they … |
The End.