I have a list containing a tuples and long integers the list looks like this:
table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)]
How do i convert the table to look like a formal list?
so the output would be:
table = ['1','1','1','2','2','2','3','3']
For information purposes the data was obtained from a mysql database.
I am doing this in my code,
HOST = '192.168.1.3'
PORT = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
query_details = {"page" : page, "query" : query, "type" : type}
s.send(str(query_details))
#data = eval(pickle.loads(s.recv(4096)))
data = s.recv(16384)
But I am continually getting EOF at the last line. The code I am sending with,
self.request.send(pickle.dumps(results))
Hi,
I create a combo box using PyGTK:
fileAttrCombo = gtk.ComboBox();
I want to attach a signal handler for this combo box. This signal handler handles when user change selection in the combo box.
What is be the best approach to do this ?
I've written the following code to illustrate the problem I'm seeing. I'm trying to use a Process.Manager.list() to keep track of a list and increment random indices of that list.
Each time there are 100 processes spawned, and each process increments a random index of the list by 1. Therefore, one would expect the SUM of the resulting list to be the same each time, correct? I get something between 203 and 205.
from multiprocessing import Process, Manager
import random
class MyProc(Process):
def __init__(self, A):
Process.__init__(self)
self.A = A
def run(self):
i = random.randint(0, len(self.A)-1)
self.A[i] = self.A[i] + 1
if __name__ == '__main__':
procs = []
M = Manager()
a = M.list(range(15))
print('A: {0}'.format(a))
print('sum(A) = {0}'.format(sum(a)))
for i in range(100):
procs.append(MyProc(a))
map(lambda x: x.start(), procs)
map(lambda x: x.join(), procs)
print('A: {0}'.format(a))
print('sum(A) = {0}'.format(sum(a)))
this is my code:
f = open('text/a.log', 'wb')
f.write('hahaha')
f.close()
and it is not create a new file when not exist
how to do this ,
thanks
updated
class MyThread(threading.Thread):
def run(self):
f = open('a.log', 'w')
f.write('hahaha')
f.close()
error is :
Traceback (most recent call last):
File "D:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "D:\zjm_code\helloworld\views.py", line 15, in run
f = open('a.log', 'w')
File "d:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1188, in __init__
raise IOError('invalid mode: %s' % mode)
IOError: invalid mode: w
Hey guys so im trying to use a while loop to add objects to a list.
Heres bascially what i want to do: (ill paste actually go after)
class x:
blah
blah
choice = raw_input(pick what you want to do)
while(choice!=0):
if(choice==1):
Enter in info for the class:
append object to list (A)
if(choice==2):
print out length of list(A)
if(choice==0):
break
((((other options))))
as im doing this i can get the object to get added to the list, but i am stuck as to how to add multiple objects to the list in the loop.
Here is my actual code i have so far...
print "Welcome to the Student Management Program"
class Student:
def init (self, name, age, gender, favclass):
self.name = name
self.age = age
self.gender = gender
self.fac = favclass
choice = int(raw_input("Make a Choice: " ))
while (choice !=0):
if (guess==1):
print("STUDENT")
namer = raw_input("Enter Name: ")
ager = raw_input("Enter Age: ")
sexer = raw_input("Enter Sex: ")
faver = raw_input("Enter Fav: ")
elif(guess==2):
print "TESTING LINE"
elif(guess==3):
print(len(a))
guess=int(raw_input("Make a Choice: "))
s = Student(namer, ager, sexer, faver)
a =[];
a.append(s)
raw_input("Press enter to exit")
any help would be greatly appreciated!
I have a directory called "notes" within the notes I have categories which are named "science", "maths" ... within those folder are sub-categories, such as "Quantum Mechanics", "Linear Algebra".
./notes
--> ./notes/maths
------> ./notes/maths/linear_algebra
--> ./notes/physics/
------> ./notes/physics/quantum_mechanics
My problem is that I don't know how to put the categories and subcategories into TWO SEPARATE list/array.
filtered=[]
text="any.pdf"
if "doc" and "pdf" and "xls" and "jpg" not in text:
filtered.append(text)
print(filtered)
This is my first Post in Stack Overflow, so excuse if there's something annoying in Question, The Code suppose to append text if text doesn't include any of these words:doc,pdf,xls,jpg.
It works fine if Its like:
if "doc" in text:
elif "jpg" in text:
elif "pdf" in text:
elif "xls" in text:
else:
filtered.append(text)
I have this HTTP Request and I want to display only the Authorization section (base64 Value) : any help ?
This Request is stored on a variable called hreq
I have tried this :
reg = re.search(r"Authorization:\sBasic\s(.*)\r", hreq)
print reg.group()
but doesn't work
Here is the request :
HTTP Request:
Path: /dynaform/custom.js
Http-Version: HTTP/1.1
Host: 192.168.1.254
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://domain.com/userRpm/StatusRpm.htm
Authorization: Basic YWhtEWa6MDfGcmVlc3R6bGH
I want to display the value YWhtEWa6MDfGcmVlc3R6bGH
Please I need your help
thanks in advance experts
I have an array that I have to add a new value to array value. I am new to arrays.
how do I loop thru the array and add to the value in the existing array.
I use this regex on some input,
[^a-zA-Z0-9@#]
However this ends up removing lots of html special characters within the input, such as
227;, #1606;, #1588; (i had to remove the & prefix so that it wouldn't show up as the actual value..)
is there a way that I can convert them to their values so that it will satisfy the regexp expression? I also have no idea why the text decided to be so big.
For example, if you have n lists of bools of the same length, then elementwise boolean AND should return another list of that length that has True in those positions where all the input lists have True, and False everywhere else.
It's pretty easy to write, i just would prefer to use a builtin if one exists (for the sake of standardization/readability).
Here's an implementation of elementwise AND:
def eAnd(*args):
return [all(tuple) for tuple in zip(*args)]
example usage:
>>> eAnd([True, False, True, False, True], [True, True, False, False, True], [True, True, False, False, True])
[True, False, False, False, True]
thx
Is it possible to get reference to class B in this example?
class A(object): pass
class B(A):
def test(self):
test2()
class C(B): pass
import inspect
def test2():
frame = inspect.currentframe().f_back
cls = frame.[?something here?]
# cls here should == B (class)
c = C()
c.test()
Basically, C is child of B, B is child of A. Then we create c of type C. Then the call to c.test() actually calls B.test() (via inheritance), which calls to test2().
test2() can get the parent frame frame; code reference to method via frame.f_code;
self via frame.f_locals['self']; but type(frame.f_locals['self']) is C (of course), but not B, where method is defined.
Any way to get B?
so, I read from DB binary field i.e. 'field1' to var Buf1, and then do something like:
unpack_from('I', Buf1, 0)
so, all is ok. but question is how can I ini Buf1 without going to DB? I can get value from DB manually and init my var statically, but how? in DB field 'field1' I see something like '0x7B0500000100000064000000B80100006'. and how can I init valid binary buffer from it?
I have a list of lists containing tuples:
[[(1L,)], [(2L,)], [(3L,)], [(4L,)], [(5L,)]
how do i edit the list so the list looks like:
l = [[1][2][3][4][5]]
I am learning Django and got it to work with wsgi. I'm following the tutorial here:
http://docs.djangoproject.com/en/1.1/intro/tutorial01/
My question is: how can I customize the look and feel of Django? Is there a repository of templates that "look good", kind of like there are for Wordpress, that I can start from? I find the tutorial counterintuitive in that it goes immediately toward customizing the admin page of Django, rather than the main pages visible to users of the site. Is there an example of a "typical" Django site, with a decent template, that I can look at and built on/modify? The polls application is again not very representative since it's so specialized.
any references on this would be greatly appreciated. thanks.
I have created some program for this.But printed a,b,c values are not correct.Please check this weather it is correct or not?
n=input("Enter the no.of McNuggets:")
a,b,c=0,0,0
count=0
for a in range(n):
if 6*a+9*b+20*c==n:
count=count+1
break
else:
for b in range(n):
if 6*a+9*b+20*c==n:
count=count+1
break
else:
for c in range(n):
if 6*a+9*b+20*c==n:
count=count+1
break
if count>0:
print "It is possible to buy exactly",n,"packs of McNuggetss",a,b,c
else:
print "It is not possible to buy"
Hey
I have to search through a list and replace all occurrences of one element with another. I know I have to first find the index of all the elements, and then replace them, but my attempts in code are getting me nowhere. Any suggestions?
I'm trying to take an existing process:
if self.path_object is not None:
dictpath = {}
for path in self.path_object:
self.params = path.pathval.split("?")[0]
self.params = path.pathval.split("&", 2)
if path.pathval.contains(self.params):
out = list(map(lambda v: v.split("=")[0] +"=" + str(self.fuzz_vectors), self.params))
else:
pass
dictpath[path] = out
print dictpath
I added the sub-if/else block in, but it is failing, stating:
AttributeError: 'unicode' object has no attribute 'contains'
on the if block .
How can I fix it?
I'm simply trying to do:
if the path.pathval has either ? or & in it:
add to dictionary
else:
pass #forget about it.
Thanks!
I am trying to retrieve source code from a webpage with an already issued cookie and write the source code to a txt file. If I remove the cookies=cookie portion I can retrieve the source code but I need to somehow send the cookie with the http.request.
output = open('Filler.txt', 'w+')
http = urllib3.PoolManager()
cookie =('users' , '1597413515')
r = http.request('http://google.com' , 'GET' , cookies=cookie)
output.write(r.data)
output.close()
I get a KeyError: None