Re: Ram memory not freed after executing python script on ubuntu system

2020-05-28 Thread Rahul Gupta
On Thursday, May 28, 2020 at 11:20:05 AM UTC+5:30, Rahul Gupta wrote:
> I am having a Ubuntu system which has 125 Gb of RAM. I executed few python 
> scripts on that system. Those scripts uses numpy arrays and pandas. Now 
> execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap 
> is occupied. At this moment nothing is running on the system. I have googled 
> it. Most of th result shows that python garbage collector is poor in 
> performance. I want this memory to be cleaned and re claim. One of the 
> easiest way is to restart the system but i dont want to restart i want a way 
> to do this when the system is up and running. Kindly tell me how to do this. 
> Thanks
Yes i am sure 125 gb of ram is there.
And you talked about refrences 
see these links
https://stackoverflow.com/questions/39100971/how-do-i-release-memory-used-by-a-pandas-dataframe
http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm
-- 
https://mail.python.org/mailman/listinfo/python-list


Ram memory not freed after executing python script on ubuntu system

2020-05-27 Thread Rahul Gupta


I am having a Ubuntu system which has 125 Gb of RAM. I executed few python 
scripts on that system. Those scripts uses numpy arrays and pandas. Now 
execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap is 
occupied. At this moment nothing is running on the system. I have googled it. 
Most of th result shows that python garbage collector is poor in performance. I 
want this memory to be cleaned and re claim. One of the easiest way is to 
restart the system but i dont want to restart i want a way to do this when the 
system is up and running. Kindly tell me how to do this. Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: error in CSV resetting with seek(0)

2020-05-02 Thread Rahul Gupta
@peter Otten thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


error in CSV resetting with seek(0)

2020-05-01 Thread Rahul Gupta
consider the following code
import csv
import numpy as np

with open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file1, 
open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file2:
csv_reader1 = csv.DictReader(csv_file1)
csv_reader2 = csv.DictReader(csv_file2)


filename = "cell_split_demo.csv"
with open("D:\PHD\obranking\\cell_split_demo.csv", 'w') as csvfilew1:
fields = (range(0, 300))
csvwriter1 = csv.DictWriter(csvfilew1, fieldnames=fields)
csvwriter1.writeheader()

for i, row in enumerate(csv_reader1):
print(f"value_i({i}) label({row['label']})")
for j, line in enumerate(csv_reader2):
if j <= i:
matrixrows[j] = []
if row['label'] != line['label']:
print(f"value_j({j})Unequal label({line['label']})")
else:
print(f"value_j({j})   equal label({line['label']})")
pass
else:
break
csv_file2.seek(0)
Here is some of the out_put samples
value_i(0) label(BW)
value_j(0)   equal label(BW)
value_i(1) label(BW)
value_j(0)   Unequal label(label)
value_j(1)   equal label(BW)
value_i(2) label(BW)
value_j(0)   Unequal label(label)
value_j(1)   equal label(BW)
value_j(2)   equal label(BW)
You can see for j=0 while i goes from 1 to n it is not able to acess 
line['label'] value.
Kindly help what is wrong with this?
-- 
https://mail.python.org/mailman/listinfo/python-list


unable to write content in csv filw

2020-04-27 Thread Rahul Gupta
FOLLWOING IS MY CODE
import pandas as pd
import csv
from sklearn.preprocessing import LabelEncoder
from sklearn.feature_selection import chi2
with open("D:\PHD\obranking\\test_chi.csv", 'w') as csvfilew1:
fields = ['index', 'feature name', 'p_value']
csvwriter1 = csv.DictWriter(csvfilew1, fieldnames=fields)
csvwriter1.writeheader()
for i in range(1, 5502):
csv_data = dict().fromkeys(fields)
csv_data['index'] = i
cols =[]
cols.append(int(0))
cols.append(int(i))

df = pd.read_csv("D:\PHD\obranking\\demo.csv", usecols=cols)
df.apply(LabelEncoder().fit_transform)
X = df.drop(labels='label', axis=1)
Y = df['label']
chi_scores = chi2(X, Y)
if(chi_scores[1] < 0.05):
f_name = str(X.columns)
f_name = f_name[8:-19]
csv_data['feature name'] = f_name
p_val = str(chi_scores[1])
p_val = p_val[1:-1]
csv_data['p_value'] = p_val
print(csv_data)
csvwriter1.writerow(csv_data)
#print(csv_data)
#print(f_name + p_val)
#print(str(X.col + str(chi_scores[1]))
test_chi.csv is created but it remains empty after execution of the code. 
although when i am printing csv_data it gets printed but not written in csv 
using writerow(csv_data). Also there are no field names in the csv even 
writeheader() seems to not work. I am confused what is wrong. Could someone 
help
-- 
https://mail.python.org/mailman/listinfo/python-list


chi square test in sklearn printing NAN values for most of the columns

2020-04-27 Thread Rahul Gupta
Hi i am trying to use chi-square Test to select most important columns among 
5501 columns. But for most of the columns i am getting NAN value as a Chi test 
value

import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.feature_selection import chi2
cols =[]
cols.append(int(0))
#for i in range(1, 5502):
cols.append(int(10))

df = pd.read_csv("D:\PHD\obranking\\demo.csv", usecols=cols)
df.apply(LabelEncoder().fit_transform)
X = df.drop(labels='label', axis=1)
Y = df['label']
chi_scores = chi2(X, Y)
print(chi_scores)
in this code i printed chi value for 10th column but for most of the columns it 
is behaving like below "C:\Users\Rahul 
Gupta\PycharmProjects\CSVLearn\venv\Scripts\python.exe" "C:/Users/Rahul 
Gupta/PycharmProjects/CSVLearn/ChiSq_learn.py" (array([nan]), array([nan]))

Process finished with exit code 0
-- 
https://mail.python.org/mailman/listinfo/python-list


Incremental PCA

2020-04-18 Thread Rahul Gupta
i wanted to implement incremental PCA.
Got this code for stack overflow but i am wondering what y = chunk.pop("y") 
does and what is this argument "y" to pop
from sklearn.decomposition import IncrementalPCA
import csv
import sys
import numpy as np
import pandas as pd

dataset = sys.argv[1]
chunksize_ = 5 * 25000
dimensions = 300

reader = pd.read_csv(dataset, sep = ',', chunksize = chunksize_)
sklearn_pca = IncrementalPCA(n_components=dimensions)
for chunk in reader:
y = chunk.pop("Y")
sklearn_pca.partial_fit(chunk)

# Computed mean per feature
mean = sklearn_pca.mean_
# and stddev
stddev = np.sqrt(sklearn_pca.var_)

Xtransformed = None
for chunk in pd.read_csv(dataset, sep = ',', chunksize = chunksize_):
y = chunk.pop("Y")
Xchunk = sklearn_pca.transform(chunk)
if Xtransformed == None:
Xtransformed = Xchunk
else:
Xtransformed = np.vstack((Xtransformed, Xchunk))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To apply pca for a large csv

2020-04-14 Thread Rahul Gupta
64 bit version
-- 
https://mail.python.org/mailman/listinfo/python-list


To apply pca for a large csv

2020-04-14 Thread Rahul Gupta
Hello all, i have a csv of 1 gb which consists of 25000 columns and 2 rows. 
I want to apply pca so i have seen sciki-learn had inbuilt fucntionality to use 
that. But i have seen to do eo you have to load data in data frame. But my 
machine is i5 with 8 gb of ram which fails to load all this data in data frame 
and shows memory error. Is there any alternative way that still i could aaply 
PCA on the same machine to the same rata set
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i am want to read data from the csv that i wrote using python csv module but apart from filed names and row count i am unable to read rest of the data

2020-04-12 Thread Rahul Gupta
@Peter Thanks alot
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i am want to read data from the csv that i wrote using python csv module but apart from filed names and row count i am unable to read rest of the data

2020-04-12 Thread Rahul Gupta




import csv
import numpy as np
with open("D:\PHD\obranking\\cell_split_demo.csv", mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
print(csv_reader.fieldnames)
col_count = print(len(csv_reader.fieldnames))
#print(sum(1 for row in csv_file))
row_count = 0

for line in enumerate(csv_reader):
print(line[csv_reader.fieldnames[1]])

@peter Otten this above one is Test10.py
@peter otten below i am posting how i created cell_split_demo.csv using test9.py
this is test9.py
import csv
import numpy as np

with open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file1, 
open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file2:
csv_reader1 = csv.DictReader(csv_file1)
csv_reader2 = csv.DictReader(csv_file2)

#csv_contents = list(csv_reader)
#for i in csv_contents:
#print(i['label'])
#print(csv_contents)

filename = "cell_split_demo.csv"
with open("D:\PHD\obranking\\cell_split_demo.csv", 'w') as csvfilew1:
fields = (range(0, 300))
csvwriter1 = csv.DictWriter(csvfilew1, fieldnames=fields)
csvwriter1.writeheader()

for i, row in enumerate(csv_reader1):
Mat = np.full([1, 300], '', dtype='object')
matrixrows = dict().fromkeys(fields)
for j, line in enumerate(csv_reader2):
if j != 300:
matrixrows[j] = []
if row['label'] != line['label']:
for k in range(1,5502):
if row[csv_reader1.fieldnames[k]] != 
line[csv_reader2.fieldnames[k]]:
if Mat[0][j] == '':
Mat[0][j] = str(k)
else:
Mat[0][j] += '#' + str(k)
#print(Mat[0][j])
print(i)
#print(j)
matrixrows[j].append(Mat[0][j])
if j == 299:
csvwriter1.writerow(matrixrows)
csv_file2.seek(0)


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i am want to read data from the csv that i wrote using python csv module but apart from filed names and row count i am unable to read rest of the data

2020-04-12 Thread Rahul Gupta
On Sunday, April 12, 2020 at 1:35:10 PM UTC+5:30, Rahul Gupta wrote:
> the cells in my csv that i wrote looks likes this 
> ['82#201#426#553#602#621#811#908#1289#1342#1401#1472#1593#1641#1794#2290#2341#2391#3023#3141#3227#3240#3525#3529#3690#3881#4406#4421#4497#4719#4722#4920#5053#5146#5433']
> and the cells which are empty looks like ['']
> i have tried the following code
> import csv
> import numpy as np
> with open("D:\PHD\obranking\\cell_split_demo.csv", mode='r') as csv_file:
> csv_reader = csv.DictReader(csv_file)
> print(csv_reader.fieldnames)
> col_count = print(len(csv_reader.fieldnames))
> print(sum(1 for row in csv_file))
> for line in csv_reader:
> print(line)
>  but when i print line it shows nothing
@Peter Otten thanks that problem got solved but now when i am trying to acess a 
particular column for every row in csv i am getting error.
the code used in addition to the above code
for line in enumerate(csv_reader):
print(line[csv_reader.fieldnames[1]])
the eoors as follows
"C:\Users\Rahul Gupta\PycharmProjects\CSVLearn\venv\Scripts\python.exe" 
"C:/Users/Rahul Gupta/PycharmProjects/CSVLearn/test10.py"
Traceback (most recent call last):
  File "C:/Users/Rahul Gupta/PycharmProjects/CSVLearn/test10.py", line 16, in 

print(line[csv_reader.fieldnames[1]])
TypeError: tuple indices must be integers or slices, not str
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', 
'14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', 
'27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', 
'40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', 
'53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', 
'66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', 
'79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', 
'92', '93', '94', '95', '96', '97', '98', '99', '100', '101', '102', '103', 
'104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', 
'115', '116', '117', '118', '119', '120', '121', '122', '123', '124', '125', 
'126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', 
'137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', 
'148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '
 158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', 
'169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', 
'180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', 
'191', '192', '193', '194', '195', '196', '197', '198', '199', '200', '201', 
'202', '203', '204', '205', '206', '207', '208', '209', '210', '211', '212', 
'213', '214', '215', '216', '217', '218', '219', '220', '221', '222', '223', 
'224', '225', '226', '227', '228', '229', '230', '231', '232', '233', '234', 
'235', '236', '237', '238', '239', '240', '241', '242', '243', '244', '245', 
'246', '247', '248', '249', '250', '251', '252', '253', '254', '255', '256', 
'257', '258', '259', '260', '261', '262', '263', '264', '265', '266', '267', 
'268', '269', '270', '271', '272', '273', '274', '275', '276', '277', '278', 
'279', '280', '281', '282', '283', '284', '285', '286', '287', '288', '289', 
'290', '291', '292', '293', '294', '295', '296', '297', '298', '299']
300

Process finished with exit code 1

-- 
https://mail.python.org/mailman/listinfo/python-list


i am want to read data from the csv that i wrote using python csv module but apart from filed names and row count i am unable to read rest of the data

2020-04-12 Thread Rahul Gupta
the cells in my csv that i wrote looks likes this 
['82#201#426#553#602#621#811#908#1289#1342#1401#1472#1593#1641#1794#2290#2341#2391#3023#3141#3227#3240#3525#3529#3690#3881#4406#4421#4497#4719#4722#4920#5053#5146#5433']
and the cells which are empty looks like ['']
i have tried the following code
import csv
import numpy as np
with open("D:\PHD\obranking\\cell_split_demo.csv", mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
print(csv_reader.fieldnames)
col_count = print(len(csv_reader.fieldnames))
print(sum(1 for row in csv_file))
for line in csv_reader:
print(line)
 but when i print line it shows nothing 
-- 
https://mail.python.org/mailman/listinfo/python-list


python file downloader not working

2017-07-25 Thread Rahul Sircar
So I recently tried to write a script using urllib2 module.
Here is the code below:
import urllib2
file = 'metasploitable-linux-2.0.0.zip'
url='https://downloads.sourceforge.net/project/metasploitable/Metasploitable2/metasploitable-linux-2.0.0.zip'
response = urllib2.urlopen(url)
fh=open(file,'w')
fh.write(response.read())
fh.close()

I am getting this error in the output.
Traceback (most recent call last):
  File "urllib_read.py", line 6, in 
fh.write(response.read())
  File "E:\Python27\lib\socket.py", line 355, in read
data = self._sock.recv(rbufsize)
  File "E:\Python27\lib\httplib.py", line 597, in read
s = self.fp.read(amt)
  File "E:\Python27\lib\socket.py", line 384, in read
data = self._sock.recv(left)
  File "E:\Python27\lib\ssl.py", line 766, in recv
return self.read(buflen)
  File "E:\Python27\lib\ssl.py", line 653, in read
v = self._sslobj.read(len)
socket.error: [Errno 10053] An established connection was aborted by the 
software in your host machine.

Please someone help me out.
-- 
https://mail.python.org/mailman/listinfo/python-list


[no subject]

2017-07-22 Thread Rahul Sircar
I wrote my code for downloading a file 'Metasploitable' using urllib2.But
it seems to have entered infinite loop.Because the screen is blank.It just
hangs there.Please have a look at my code.

import urllib2
file = 'metasploitable-linux-2.0.0.zip'
url='
https://downloads.sourceforge.net/project/metasploitable/Metasploitable2/metasploitable-linux-2.0.0.zip
'
response = urllib2.urlopen(url)
fh=open(file,'w')
fh.write(response.read())
fh.close()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Combining every pair of list items and creating a new list.

2017-07-18 Thread Rahul K P
You can use a simple logic and list comprehension.

so it will be like this

lst = [1, 2, 3, 4, 5, 6, 7, 8]
print [lst[i:i+2] for i in range(0,len(lst),2)]

Here 2 is the pairing number, You can set is as your need.



On Tue, Jul 18, 2017 at 1:40 AM,  wrote:

> Hi,
>
> I'm having difficulty thinking about how to do this as a Python beginner.
>
> But I have a list that is represented as:
>
> [1,2,3,4,5,6,7,8]
>
> and I would like the following results:
>
> [1,2] [3,4] [5,6] [7,8]
>
> Any ideas?
>
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards
*Rahul K P*

Python Developer
Mumbai
+919895980223
-- 
https://mail.python.org/mailman/listinfo/python-list


do_POST not working on http.server with python

2016-04-28 Thread Rahul Raghunath
 0
down vote
favorite


I'm trying to create a simple http server with basic GET and POST 
functionality. The program is supposed to GET requests by printing out a simple 
webpage that greets a user and askes how he would rather be greeted. When the 
user enters a greeting of his choice, the webpage should now greet him as he 
had chosen.

While GET seems to be working fine, POST is not. I tried debugging by printing 
at every code execution and it seems to be getting stuck here:

ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))

I'll paste the code full code below, along with my terminal output.

Code:

from http.server import BaseHTTPRequestHandler, HTTPServer
import cgi


class webServerHandler(BaseHTTPRequestHandler):

def do_GET(self):
try:
if self.path.endswith("/hello"):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
output = ""
output += ""
output += "Hello!"
output += '''What would you like me to 
say? '''
output += ""
self.wfile.write(output.encode(encoding = 'utf_8'))
print (output)
return

if self.path.endswith("/hola"):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
output = ""
output += ""
output += "¡ Hola !"
output += '''What would you like me to 
say? '''
output += ""
self.wfile.write(output.encode(encoding = 'utf_8'))
print (output)
return

except IOError:
self.send_error(404, 'File Not Found: %s' % self.path)

def do_POST(self):
try:
self.send_response(201)
print("Sent response")
self.send_header('Content-type', 'text/html')
print("Sent headers")
self.end_headers()
print("Ended header")
ctype, pdict = 
cgi.parse_header(self.headers.getheader('content-type'))
print("Parsed headers")
if ctype == 'multipart/form-data':
fields = cgi.parse_multipart(self.rfile, pdict)
messagecontent = fields.get('message')
print("Receiver message content")
output = ""
output += ""
output += "  Okay, how about this: "
output += " %s " % messagecontent[0]
output += '''What would you like me to say? '''
output += ""
print(output)
self.wfile.write(output.encode(encoding = 'utf_8'))
print ("Wrote through CGI")
except:
pass


def main():
try:
port = 8080
server = HTTPServer(('', port), webServerHandler)
print ("Web Server running on port", port)
server.serve_forever()
except KeyboardInterrupt:
print (" ^C entered, stopping web server")
server.socket.close()

if __name__ == '__main__':
main()

Terminal Output:

Web Server running on port 8080
127.0.0.1 - - [28/Apr/2016 13:28:59] "GET /hello HTTP/1.1" 200 -
Hello!What would you like me to 
say? 
127.0.0.1 - - [28/Apr/2016 13:29:09] "POST /hello HTTP/1.1" 201 -
Sent response
Sent headers
Ended header

As you can see, the POST function does not seem to go beyong the parse_header 
command. I cannot figure this out, and any help would be usefu!
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: PROBLEM IN INSTALLATION

2015-07-16 Thread rahul tiwari
I want to import PIL package but every time this is showing error " no PIL
 module find" .

plz suggest me  how  i can fix this problem.

-- 




-- 
Rahul Tiwari
Research Engineer
Robospecies Technology Pvt. Ltd.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pythonw.exe has stopped working

2014-09-12 Thread Rahul Bhagat
On Friday, 12 September 2014 11:18:25 UTC+5:30, Rahul Bhagat  wrote:
> Hello Folks,
> 
> 
> 
> I'm using RIDE -- Robot Framework Test Data Editor
> 
> RIDE 1.3 running on Python 2.7.6. 
> 
> 
> 
> When I click on some of my test case the RIDE GUI hangs and gives bellow 
> error message.
> 
> 
> 
> 
> 
> [Window Title]
> 
> pythonw.exe
> 
> 
> 
> [Main Instruction]
> 
> pythonw.exe has stopped working
> 
> 
> 
> [Content]
> 
> A problem caused the program to stop working correctly. Windows will close 
> the program and notify you if a solution is available.
> 
> 
> 
> [Close program]
> 
> 
> 
> 
> 
> It's strange that while it's able to open other test cases but fails on one 
> particular test case. The distinguishing  fact about the test case is that it 
> is a big one using lots of keywords.
> 
> 
> 
> I know it might work if I split my test case but have any of you encountered 
> this problem and knows how to fix it ? some fix like providing more memory or 
> specifying some parameter when pythonw.exe starts?
> 
> 
> 
> 
> 
> Thank you very much  in advance.
> 
> 
> 
> Cheers,
> 
> 
> 
> Rahul.



UPDATE:


Additional Windows Log


Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: pythonw.exe
  Application Version:  0.0.0.0
  Application Timestamp:527fcf67
  Fault Module Name:wxmsw28uh_core_vc.dll
  Fault Module Version: 2.8.12.1
  Fault Module Timestamp:   4e21188a
  Exception Code:   c005
  Exception Offset: 0002516e
  OS Version:   6.1.7601.2.1.0.256.48
  Locale ID:1033
  Additional Information 1: af6f
  Additional Information 2: af6f3f0509d68fb0a703e2e9a01d8095
  Additional Information 3: 14ba
  Additional Information 4: 14ba7bfab2274826d4d9f81374905fca

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy 
statement offline:
  C:\Windows\system32\en-US\erofflps.txt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQL dymanic query in Python

2013-05-30 Thread RAHUL RAJ
On Wednesday, May 29, 2013 3:32:51 PM UTC+5:30, Fábio Santos wrote:
> On 29 May 2013 10:13, "RAHUL RAJ"  wrote:
> 
> >
> 
> > Can anyone tell me the proper way in which I can execute dynamic MySQL 
> > queries in Python?
> 
> >
> 
> > I want to do dynamic queries for both CREATE and INSERT statement.
> 
> >
> 
> > Here is my attempted code:
> 
> >
> 
> >
> 
> > sql="create table %s (%%s, %%s, %%s ... )" % (tablename,''.join(fields)+' 
> > '.join(types))
> 
> > cur.execute(sql)
> 
> >
> 
> >
> 
> > where 'field' is the fieldnames stored in a list and 'types' are the 
> > fieldtypes stored in a list.
> 
> You need to join the fields and the field types. Use zip().
> 
> Then join with commas.
> 
> fields_and_types = ['%s %s' % (field, type) for field, type in zip(fields, 
> types)]
> 
> what_goes_between_the_parens = ', '.join(fields_and_types)
> 
> sql = 'create table %s (%s)' % (tablename, what_goes_between_the_parens)
> 
> See where that gets you.

Fantastic! It worked, Thanks :)
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQL dymanic query in Python

2013-05-29 Thread RAHUL RAJ
Can anyone tell me the proper way in which I can execute dynamic MySQL queries 
in Python?

I want to do dynamic queries for both CREATE and INSERT statement.

Here is my attempted code:


sql="create table %s (%%s, %%s, %%s ... )" % (tablename,''.join(fields)+' 
'.join(types))
cur.execute(sql)  


where 'field' is the fieldnames stored in a list and 'types' are the fieldtypes 
stored in a list. 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Append to python List

2013-05-09 Thread RAHUL RAJ
I'm getting same output for both code parts, why not for th code parts in 
question?

On Thursday, May 9, 2013 1:48:51 PM UTC+5:30, RAHUL RAJ wrote:
> Then what about this code part?
> 
> 
> 
> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
> 
> 
> 
> and the following code part:
> 
> 
> 
> for x in [1,2,3]:
> 
>   for y in [3,1,4]:
> 
> if x != y:
> 
>   combs.append((x, y))
> 
> 
> 
> 
> 
> On Thursday, May 9, 2013 12:24:24 PM UTC+5:30, Gary Herron wrote:
> 
> > On 05/08/2013 11:36 PM, RAHUL RAJ wrote:
> 
> > 
> 
> > > Checkout the following code:
> 
> > 
> 
> > >
> 
> > 
> 
> > > sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y]
> 
> > 
> 
> > > output=[]
> 
> > 
> 
> > 
> 
> > 
> 
> 
> 
> 
> 
> > > output=[x for x in sample2 if x not in output]
> 
> > 
> 
> > This statement is not doing what you expect.  It is not building a list 
> 
> > 
> 
> > in the variable named output, it is building a list (anonymously) then 
> 
> > 
> 
> > binding it to the variable output once it's built.  Therefore output is 
> 
> > 
> 
> > [] for the whole list building operation.
> 
> > 
> 
> > 
> 
> > 
> 
> > The later operation works, because your *are* building the list in place 
> 
> > 
> 
> > as you go.
> 
> > 
> 
> > 
> 
> > 
> 
> > >
> 
> > 
> 
> > > the output I get is
> 
> > 
> 
> > > 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 
> > > 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 
> > > 13 14 15 17 10 11 12 13 14 15 16 17
> 
> > 
> 
> > >
> 
> > 
> 
> > > which contains duplicate values.
> 
> > 
> 
> > >
> 
> > 
> 
> > >
> 
> > 
> 
> > >
> 
> > 
> 
> > >
> 
> > 
> 
> > > But if I do like this:
> 
> > 
> 
> > >
> 
> > 
> 
> > > sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y]
> 
> > 
> 
> > > output=[]
> 
> > 
> 
> > > for x in sample2:
> 
> > 
> 
> > >if x not in output:
> 
> > 
> 
> > >   output.append(x)
> 
> > 
> 
> > >
> 
> > 
> 
> > >
> 
> > 
> 
> > > the value of 'output' I get like this:
> 
> > 
> 
> > > 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
> 
> > 
> 
> > >
> 
> > 
> 
> > > I know that both the programs have the same functionality, but why do I 
> > > have different outputs?
> 
> > 
> 
> > >
> 
> > 
> 
> > > Please help!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Append to python List

2013-05-09 Thread RAHUL RAJ
Then what about this code part?

[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]

and the following code part:

for x in [1,2,3]:
  for y in [3,1,4]:
if x != y:
  combs.append((x, y))


On Thursday, May 9, 2013 12:24:24 PM UTC+5:30, Gary Herron wrote:
> On 05/08/2013 11:36 PM, RAHUL RAJ wrote:
> 
> > Checkout the following code:
> 
> >
> 
> > sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y]
> 
> > output=[]
> 
> 
> 


> > output=[x for x in sample2 if x not in output]
> 
> This statement is not doing what you expect.  It is not building a list 
> 
> in the variable named output, it is building a list (anonymously) then 
> 
> binding it to the variable output once it's built.  Therefore output is 
> 
> [] for the whole list building operation.
> 
> 
> 
> The later operation works, because your *are* building the list in place 
> 
> as you go.
> 
> 
> 
> >
> 
> > the output I get is
> 
> > 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 
> > 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 
> > 14 15 17 10 11 12 13 14 15 16 17
> 
> >
> 
> > which contains duplicate values.
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > But if I do like this:
> 
> >
> 
> > sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y]
> 
> > output=[]
> 
> > for x in sample2:
> 
> >if x not in output:
> 
> >   output.append(x)
> 
> >
> 
> >
> 
> > the value of 'output' I get like this:
> 
> > 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
> 
> >
> 
> > I know that both the programs have the same functionality, but why do I 
> > have different outputs?
> 
> >
> 
> > Please help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Append to python List

2013-05-08 Thread RAHUL RAJ
Checkout the following code:

sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y]   
output=[]
output=[x for x in sample2 if x not in output]

the output I get is
3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 7 8 
9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 14 15 17 
10 11 12 13 14 15 16 17

which contains duplicate values.




But if I do like this:

sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y]   
output=[]
for x in sample2:
  if x not in output:
 output.append(x)


the value of 'output' I get like this:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

I know that both the programs have the same functionality, but why do I have 
different outputs?

Please help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul
When I use same code base for Python 3.x, then behavior is different. In this 
when I return false then also it throws exception but only when any other 
statement get executed after this 

like below code:
 ...
 ...
   b = None
   try:
 a = testModule.check(None)
   except:
 b = sys.exc_info()
then code execution doesn't come to except block.
But when I add one statement after calling check function then code execution 
goes into except block. 

 ...
 ...
 b = None
 try:
   a = testModule.check(None)
   print( a )
 except:
   b = sys.exc_info()


On Thursday, 2 August 2012 15:07:08 UTC+5:30, Tim Golden  wrote:
> On 02/08/2012 10:21, rahul wrote:
> 
> > 
> 
> > Hi TJG,
> 
> > 
> 
> > The above link also doesn't strictly said that return value should be
> 
> > NULL only, it only said that usually NULL pointer used. No where I
> 
> > saw that it is nessasory t
> 
> > 
> 
> > At http://docs.python.org/c-api/exceptions.html. it is written that
> 
> > "Most functions also return an error indicator, usually NULL if they
> 
> > are supposed to return a pointer, or -1 if they return an integer
> 
> > (exception: the PyArg_*() functions return 1 for success and 0 for
> 
> > failure)." this also told that usually NULL is used but we can change
> 
> > the return error indicator to any value. As like PyArg_*() used 0 for
> 
> > error value.
> 
> 
> 
> The docs you quote are very slightly confusing because they're combining
> 
> the standard practice (return NULL), the uncommon alternative (return
> 
> -1) and a few special cases present in the core functions.
> 
> 
> 
> In short, any function you expose in an extension module will be
> 
> returning a PyObject* and should return NULL if it is setting or
> 
> cascading an exception.
> 
> 
> 
> I'm not convinced that the docs need altering here: this is the first
> 
> time I've come across anyone who was confused. But if you think some
> 
> different wording might help, feel free to propose something.
> 
> 
> 
> TJG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul

Hi TJG,

The above link also doesn't strictly said that return value should be NULL 
only, it only said that usually NULL pointer used. No where I saw that it is 
nessasory t

At http://docs.python.org/c-api/exceptions.html. it is written that "Most 
functions also return an error indicator, usually NULL if they are supposed to 
return a pointer, or -1 if they return an integer (exception: the PyArg_*() 
functions return 1 for success and 0 for failure)." this also told that usually 
NULL is used but we can change the return error indicator to any value. As like 
PyArg_*() used 0 for error value.

Thanks,
Rahul
-- 
http://mail.python.org/mailman/listinfo/python-list


C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul
I am implementing a C extension module, during this I saw that when I set the 
global error indicator and error message through PyErr_SetString() API and 
return false.

But it doesn't throw any error when I tried to check the error through 
sys.exc_info() then it returns (NULL, NULL, NULL) tuple. 

When I return NULL through the C extension module's function then it works 
correctly and throws the exception as expected.

The skeleton looks like:

static PyObject* check(PyObject* sef, PyObject* args)
{
PyObject* input = NULL;
if (!PyArg_ParseTuple(args, "O", &input)){
 return NULL;
}
.
.
PyErr_SetString(PyExc_Exception, "Throwing Error through check 
function");
Py_RETURN_FALSE;
}

Any idea on why this is happening? Any help will be appreciated.

Thanks,
Rahul
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Weekly

2011-09-26 Thread Rahul
Hi Everyone,

I have started a free weekly newsletter called Python Weekly which
includes curated news, articles, new releases, software & tools,
events, jobs etc about Python and related technologies. It's a great
way to keep abreast of what's happening in Python land. You can
subscribe to it here, http://www.pythonweekly.com/

Regards
Rahul Chaudhary
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Struggling to convert a mysql datetime object to a python string of a different format

2011-02-24 Thread rahul mishra
try this 

test = time.time(2011, 2, 1, 2, 4, 10)
# this is your datetime object from mysql

print time.mktime(test.timetuple())

hope this would help you


> On Wednesday, August 04, 2010 7:40 PM ? wrote:

> Okey, i have many hours now struggling to convert a mysql datetime
> field that i retreive to a string of this format '%d %b, %H:%M'
> 
> I google a lot but couldnt found out how to format it being a string
> 
> Here si the code so far:
> 
> try:
> cursor.execute( ''' SELECT host, hits, date FROM visitors WHERE page
> =3D '%s' ORDER BY date DESC ''' % (page) )
> except MySQLdb.Error:
> print( "Error %d: %s" % (e.args[0], e.args[1]) )
> else:
> print ( ''' ( =C5=F0=E9=F3=EA=DD=F0=F4=E7=F2 ) - ( =
> =C5=F0=E9=F3=EA=DD=F8=E5=E9=F2 )
> - ( =C7=EC=E5=F1=EF=EC=E7=ED=DF=E1 ) ''' )
> print ( '' )
> 
> results =3D cursor.fetchall()
> 
> for row in results:
> print ( '''  ''' )
> 
> for entry in row:
> entry =3D datetime.datetime.strftime( entry, '%d %b, %H:%M' ) #!!!
> this is wrong!
> print ( '''  %s  ''' % entry )
> 
> sys.exit(0)
> 
> Apart from that i do not know how iam supposed to print it, because the
> date string is the 3rd string in every row of the dataset.
> 
> Please help me out!


>> On Thursday, August 05, 2010 4:55 AM Dennis Lee Bieber wrote:

>> gmane.comp.python.general:
>> 
>> As you state, it is the third item in each returned row... So why
>> are you trying to treat EVERY item in the row as a date?
>> 
>> Since MySQLdb appears to return datetime objects (my quick test is
>> showing datetime.date for dates in a test database) you should be
>> probably be using
>> 
>> formatted_entry = entry.strftime("%d... %M")
>> 
>> to do the formatting as string
>> 
>> 
>> 
>> --
>> Wulfraed Dennis Lee Bieber AF6VN
>> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/


>>> On Thursday, August 05, 2010 12:31 PM ? wrote:

>>> rote:
>>> r entry in row:
>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0entry =3D datetime.datetime.strftime( entry, '%d=
>>> %b, %H:%M' ) #!!!
>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0print ( '''  %s  ''' % entry )
>>> turned row... So why
>>> 
>>> Because when i try to prin the 3 items liek that
>>> 
>>> print row[0], row[1], row[2]
>>> 
>>> it gives me an error, so i dont knwo how to tell it how to print the
>>> 3rd item differently.
>>> 
>>> 
>>> 
>>> cts (my quick test is
>>> )
>>> 
>>> I tried that myself yesterday but look it fails to the following
>>> message
>>> 
>>> /home/webville/public_html/cgi-bin/index.py
>>> 63
>>> 64 for entry in row:
>>> 65 formatted_entry =3D
>>> entry.strftime('%d %b, %H:%M')
>>> 66 print ( '''  %s  ''' %
>>> entry )
>>> 67
>>> formatted_entry undefined, entry =3D '178-124-186.dynamic.cyta.gr',
>>> entry.strftime undefined
>>> AttributeError: 'str' object has no attribute 'strftime'
>>> args =3D ("'str' object has no attribute 'strftime'",)


 On Thursday, August 05, 2010 2:52 PM ? wrote:

 Hey i made it! :-)
 
 dataset = cursor.fetchall()
 
 for row in dataset:
 print ( '''  ''' )
 
 date = row[2].strftime( '%d %b, %H:%M' )
 
 print ( '''  %s%s %s  ''' %
 ( row[0], row[1], date ) )
 
 Unfortunately had to ditch the 'for entry in row' line because
 could not iterate over the items of the row.
 
 Could you please shoe me how could i do the same thing with
 iteration?!
 Thanks!


> On Thursday, August 05, 2010 3:09 PM Tim Chase wrote:

> On 08/05/10 13:52, ?? wrote:
> 
> Well, depending on whether "row" is a tuple or a list, you can do
> either
> 
> row[2] = row[2].strftime(...)  # if it is a list
> 
> or you can just iterate over a predefined list/tuple:
> 
> for row in dataset:
> print ("")
> for item in (row[0], row[1], row[2].strftime(...)):
> print ("%s print ("")
> 
> Though I think I'd make it a bit clearer by naming the fields:
> 
> for host, hits, dt in dataset:
> print ("")
> for item in (host, hits, dt.strftime(...)):
> print ("%s" % item)
> print ("")
> 
> Or perhaps even just
> 
> print ("".join("%s" % item
> for item in (host, hits, dt.strftime(...))
> )
> 
> Whichever you prefer.  I think I am partial to the 2nd-from-last
> version, especially as the list of fields may grow.
> 
> -tkc


>> On Thursday, August 05, 2010 5:01 PM ? wrote:

>> As i have it the returned 'dataset' is stored line per line to 'row'.
>> 
>> So,
>> 'dataset' in here is a 'list of tuples' right?
>> and
>> 'row' in here is a tuple form the above list of tuples right?
>> 
>> Am i understanding this correctly?!
>> 
>> 
>> 
>> It was a tuple. But it migth as well be a list too?!?!
>> 
>> Could 'dataset' be a 'list of lists' as well?
>> 
>> How one would know 

Re: Python API Functions equivalent to ruby's rb_big2str() and rb_str2cstr()

2009-05-12 Thread rahul
On May 12, 5:25 pm, Christian Heimes  wrote:
> rahul schrieb:
>
> > Is functions equivalent to ruby's  rb_big2str() and rb_str2cstr()
> > available in Python.
> > I had search a lot in google but not able to find that.
> > If anybody know than please give me the name of those functions of
> > Python.
>
> Please don't assume that we know what the Ruby functions are doing. You
> need to explain them or at least provide a link to some docs.
>
> Christian

Hi Christian,
  rb_big2str(Big-Integer, base) of ruby returns string representation
of big-Integer. now, i am able to find equivalent python API function
of rb_str2cstr() of ruby.
so , please help me about rb_big2str(Big-Integer, base) equivalent of
Python API function which i can use in extended module in c.

---
 rahul

---
rahul
-- 
http://mail.python.org/mailman/listinfo/python-list


Python API Functions equivalent to ruby's rb_big2str() and rb_str2cstr()

2009-05-12 Thread rahul
Is functions equivalent to ruby's  rb_big2str() and rb_str2cstr()
available in Python.
I had search a lot in google but not able to find that.
If anybody know than please give me the name of those functions of
Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-28 Thread Rahul
On Apr 28, 5:07 pm, Tim Hoffman  wrote:
> On Apr 28, 7:50 pm, Rahul  wrote:
>
>
>
> > On Apr 28, 1:02 pm, Marco Mariani  wrote:
>
> > > Rahul wrote:
> > > > 1) Do you have any idea about web based support (like mod_python)
> > > > provided by python.org (official web site)
>
> > > > Details: - As we know mod_python is used for embeding python code into
> > > > apache server.
> > > > so, i want to know whether mod_python is officially supported by
> > > > python.org or if there is
> > > > other such framework for embeding python on web server
>
> > > Forget about mod_python, everything else is better.
>
> > > This list (the first result upon googling for "python web frameworks")
> > > is actually up to date, and a good start.
>
> > >http://wiki.python.org/moin/WebFrameworks
>
> > > Just don't ask which one is best for everything, or which one is The
> > > Official Standard Way Of Doing Things.
>
> > but i want to know which is the official standard recommended by
> > python.
>
> But there isn't
>
> There are a number of frameworks out there each with there own set of
> strengths and weaknesses,  you shoul dbe
> looking at each ones vibrancy (community), suitablility for your
> application, etc...
>
> T
>
> T

Thanks tim
This information was really of help to me
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-28 Thread Rahul
On Apr 28, 1:02 pm, Marco Mariani  wrote:
> Rahul wrote:
> > 1) Do you have any idea about web based support (like mod_python)
> > provided by python.org (official web site)
>
> > Details: - As we know mod_python is used for embeding python code into
> > apache server.
> > so, i want to know whether mod_python is officially supported by
> > python.org or if there is
> > other such framework for embeding python on web server
>
> Forget about mod_python, everything else is better.
>
> This list (the first result upon googling for "python web frameworks")
> is actually up to date, and a good start.
>
> http://wiki.python.org/moin/WebFrameworks
>
> Just don't ask which one is best for everything, or which one is The
> Official Standard Way Of Doing Things.

but i want to know which is the official standard recommended by
python.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-28 Thread Rahul
1) Do you have any idea about web based support (like mod_python)
provided by python.org (official web site)

Details: - As we know mod_python is used for embeding python code into
apache server.
so, i want to know whether mod_python is officially supported by
python.org or if there is
other such framework for embeding python on web server

Thanks,

Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-27 Thread Rahul
> > 2) I have my web based application written using mod_python
> > a. It should be more based on framework type.
> > b. It should have all the features present in mod_python.
>
> These two goals conflict.  You'll need to use your brain to discover
> what is best for your application.  In general "have all the features
> of" and "but better" conflict.
>
> --Scott David Daniels
> scott.dani...@acm.org

hi scott,

i am getting more specific, is there any web development framework
better than mod python which is
easy to maintain.

thanks

rahul
--
http://mail.python.org/mailman/listinfo/python-list


is PyCodec_Encode API able to change encoding fron UCS-2 to UCS-4

2009-04-27 Thread rahul

is this generic API can be use to change ucs-2 to ucs-4
PyObject *  PyCodec_Encode(
   PyObject *object,
   const char *encoding,
   const char *errors
   );

if yes than what is the format of denoting ucs-4, because i try to do
that but all times i got segmentation fault, i used "ucs-4-le" for
little endian system and "ucs-4-be"  for big endian system to set
ucs-4 encoding.

-
Rahul Priyadarshi
--
http://mail.python.org/mailman/listinfo/python-list


is PyCodec_Encode API able to change encoding fron UCS-2 to UCS-4

2009-04-27 Thread rahul

is this generic API can be use to change ucs-2 to ucs-4
PyObject *  PyCodec_Encode(
   PyObject *object,
   const char *encoding,
   const char *errors
   );

if yes than what is the format of denoting ucs-4, because i try to do
that but all times i got segmentation fault, i used "ucs-4-le" for
little endian system and "ucs-4-be"  for big endian system to set
ucs-4 encoding.
--
http://mail.python.org/mailman/listinfo/python-list


Web based application development using python

2009-04-27 Thread Rahul
Hello all,

I have two questions
1)  When will be python3.1 (final) get released? (The date should be
appropriate (proposed), it must be the span in between which there are
chances of release)
2)  I have my web based application written using mod_python but was
needed to know if there is better option other than mod_python to
develop web based applications in python which can be easy to maintain
and debug?
a.  It should be more based on framework type.
b.  It should have all the features present in mod_python.
c.  Client-server driven architecture support.

Any help regarding will be greatly appreciated.


Thanks & Regards,

Rahul Warhekar
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with PyMapping_SetItemString()

2009-04-21 Thread rahul
On Apr 22, 12:17 am, Stefan Behnel  wrote:
> rahul wrote:
> > tatic PyObject *upadteCheck(PyObject *self,PyObject *args){
> >    PyObject *var_pyvalue=NULL,*newVar_pyvalue=NULL,*dict=NULL;
> >    char *varName;
>
> >    if (!PyArg_ParseTuple(args, "s", &varName)){
> >                 return NULL;
> >       }
> >      dict=PyEval_GetLocals();
> >      var_pyvalue=PyMapping_GetItemString(dict,varName);
>
> >      if(inObject==NULL){
> >            dict=PyEval_GetGlobals();
> >            var_pyvalue=PyMapping_GetItemString(dict,varName);
> >      }
>
> what's "inObject"?
>
> Stefan

Hi Stefan,
   That was due to type error, "inObject" is actually "var_pyvalue"


   rahul
--
http://mail.python.org/mailman/listinfo/python-list


problem with PyMapping_SetItemString()

2009-04-21 Thread rahul
i have a c extension

tatic PyObject *upadteCheck(PyObject *self,PyObject *args){
PyObject *var_pyvalue=NULL,*newVar_pyvalue=NULL,*dict=NULL;
char *varName;

if (!PyArg_ParseTuple(args, "s", &varName)){
return NULL;
  }
  dict=PyEval_GetLocals();
  var_pyvalue=PyMapping_GetItemString(dict,varName);

  if(inObject==NULL){
dict=PyEval_GetGlobals();
var_pyvalue=PyMapping_GetItemString(dict,varName);
  }

  printf("\n input value for variable %s is :  %s
\n",varName,PyString_AsString(var_pyvalue))

  newVar_pyvalue=Py_BuildValue("s","value changed");

  PyMapping_SetItemString(dict,varname,newVar_pyvalue);

  return Py_BuildValue("");

}

and i have three  test cases for this extension

1.(name test1.py)
 import upadteCheck
 var1= "abcd"

 func1():
 updateCheck.updateCheck("var1")
 print var1

2.(name test2.py)
import upadteCheck
 var1= "abcd"
 updateCheck.updateCheck("var1")
 print var1

3.(name test3.py)
 import upadteCheck

 func1():
 var1= "abcd"
 updateCheck.updateCheck("var1")
 print var1

if i run these three test cases like
 1.   import test1
   test1.fun1()

 2.   python test2

 3. import test3
 test3.func1()

than first two test cases runs correctly and gives result for var1
"value changed"  but 3rd test case not gives correct result and value
of var1 remains "abcd"

why this happen and how i correct it ??
--
http://mail.python.org/mailman/listinfo/python-list


problem with PyMapping_SetItemString()

2009-04-21 Thread rahul
i have a c extension

tatic PyObject *upadteCheck(PyObject *self,PyObject *args){
PyObject *var_pyvalue=NULL,*newVar_pyvalue=NULL,*dict=NULL;
char *varName;

if (!PyArg_ParseTuple(args, "s", &varName)){
return NULL;
  }
  dict=PyEval_GetLocals();
  var_pyvalue=PyMapping_GetItemString(dict,varName);

  if(inObject==NULL){
dict=PyEval_GetGlobals();
var_pyvalue=PyMapping_GetItemString(dict,varName);
  }

  printf("\n input value for variable %s is :  %s
\n",varName,PyString_AsString(var_pyvalue))

  newVar_pyvalue=Py_BuildValue("s","value changed");

  PyMapping_SetItemString(dict,varname,newVar_pyvalue);

  return Py_BuildValue("");
}



and i have three  test cases for this extension

1.(name test1.py)
 import upadteCheck
 var1= "abcd"

 func1():
 updateCheck.updateCheck(var1)
 print var1


2.(name test2.py)
import upadteCheck
 var1= "abcd"
 updateCheck.updateCheck(var1)
 print var1

3.(name test3.py)
 import upadteCheck

 func1():
 var1= "abcd"
 updateCheck.updateCheck(var1)
 print var1

if i run these three test cases like
 1.   import test1
   test1.fun1()

 2.   python test2

 3. import test3
 test3.func1()

than first two test cases runs correctly and gives result for var1
"value changed"  but 3rd test case not gives correct result and value
of var1 remains "abcd"


why this happen and how i correct it ??
--
http://mail.python.org/mailman/listinfo/python-list


is PyCodec_Encode() API returns New reference or Borrowed reference

2009-04-20 Thread rahul
Is  PyCodec_Encode(PyObject *object,char *encoding,char *errors )
returns New reference or Borrowed reference

--
http://mail.python.org/mailman/listinfo/python-list


Re: how to know argument name with which a function of extended c called

2009-04-15 Thread rahul
On Apr 14, 6:24 pm, John Machin  wrote:
> On Apr 14, 10:35 pm, rahul  wrote:
>
> > Hi,
> >   i need to write a 'c extension function' in this function i need to
> > change argument value with  which this function called.
>
> The appropriate way for a function to give output is to return a
> value, or a tuple of values.
>
> example:
>
> def get_next_token(input_buffer, offset):
>    """get next lexical token, starting at offset
>       return (the_token, new offset)"""
>    length = find_len_of_token_somehow(input_buffer, offset)
>    new_offset = offset + length
>    return input_buffer[offset:new_offset], new_offset
>
> and you can call it by
>    token, pos = get_next_token(buff, pos)
>    return input
>
> >   ie,
> >          if a python code like
> >             import changeValue as c
> >             arg="old value"
> >             c.changeValue(arg)
> >             print arg
>
> Fortunately, you can't construct such a thing in Python or in a C
> extension. Consider the following:
>
> print "two", 2
> c.changeValue(2)
> print "two maybe", 2
>
> What would you want to it to print the second time?
> two maybe new value?
>
>
>
> >  then it print "new value"
>
> >  i write code like this..
>
> > static PyObject *changeValue(PyObject *self,PyObject *args){
> >         PyObject *sampleObj, *m ;
> >         char *argName;
>
> >       if (!PyArg_ParseTuple(args, "O", &sampleObj)){
> >                 return NULL;
> >       }
>
> >    m = PyImport_AddModule("__main__");
>
> This means you are assuming/hoping this function will be called only
> from the main script ...
>
> >    PyObject_SetAttrString(m, argName, "new value");
>
> Even if you know the name, you have the problem that it is changing
> the __main__ module's globals ... but the arg could be local or it
> could be an expression ...
>
> >    return Py_BuildValue("");
>
> > }
>
> > But for this i need to know the argument name with which this function
> > called .
> > Is this possible to know argument name in extended c function? if yes,
> > than how i can do it???
>
> No, it's not possible to know the argument name (without help from the
> caller e.g. keyword args), it may not even have a name, it may have
> multiple names ... this is just another variation of the old "what is
> the name of my object" FAQ.
>
> Why don't you tell us what you are trying to achieve (a higher-level
> goal than "I need to poke some value at/into some variable of doubtful
> name and unknowable location"), and then we might be able to give you
> some ideas.
>
> HTH,
> John




Hi John,
   thanks for your great full information,
 But, In my project anyhow i have to change argument value in some
cases. can we pass pointer  of an variable in extended c function.

  like
 import changeValue as c
arg="old value"
c.changeValue(&arg)
print arg

if yes, then how pointer of this variable handle through extended c
function. and how we can change the value through pointer.


Rahul priyadarshi
--
http://mail.python.org/mailman/listinfo/python-list


how to know argument name with which a function of extended c called

2009-04-14 Thread rahul
Hi,
  i need to write a 'c extension function' in this function i need to
change argument value with  which this function called.
  ie,
 if a python code like
import changeValue as c
arg="old value"
c.changeValue(arg)
print arg

 then it print "new value"

 i write code like this..

static PyObject *changeValue(PyObject *self,PyObject *args){
PyObject *sampleObj, *m ;
char *argName;

  if (!PyArg_ParseTuple(args, "O", &sampleObj)){
return NULL;
  }

   m = PyImport_AddModule("__main__");
   PyObject_SetAttrString(m, argName, "new value");
   return Py_BuildValue("");
}

But for this i need to know the argument name with which this function
called .
Is this possible to know argument name in extended c function? if yes,
than how i can do it???
--
http://mail.python.org/mailman/listinfo/python-list


Re: what does "execfile" mean within profiler output and why does it not have a attached line number

2009-04-06 Thread Rahul
Robert Kern  wrote in
news:mailman.3316.1238893185.11746.python-l...@python.org: 

> To quickly find your hotspots, start by sorting by 'time' (that would
> be displayed as the 'tottime' column in the human-readable output).
> That tells you how much time is spent in each function itself,
> excluding the time it spends calling out to other functions. For
> example, per the docs under "Instant Userƒ Ts Manual" (which you might
> want to spend a little more time with): 
> 
>p.sort_stats('time').print_stats(10)
> 
> 

Thanks Robert. I was executing the profiler on the commandline like so:

python -m profile ~/bin/visualize.py *.nc

Is there any way to pass further options of the form sort etc. via this 
invocation. The manual did not specify usage of this form.

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: cProfile.py not found.

2009-04-04 Thread Rahul
John Machin  wrote in news:0a8400dc-b14b-4bb9-a608-
7327fe88a...@j18g2000prm.googlegroups.com:

> Read the fantastic manual:
> 
> http://docs.python.org/library/profile.html
 [snip]
>   cProfile is recommended for most users; it's a C extension with
> reasonable overhead that makes it suitable for profiling long-running
> programs. Based on lsprof, contributed by Brett Rosen and Ted Czotter.
> 
>   New in version 2.5.
> 

Thanks John; I did read the manual which is why I decided to use cProfile 
as it was "recommended for most users".  I missed the last bit about "New 
in version 2.5." 

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


what does "execfile" mean within profiler output and why does it not have a attached line number

2009-04-04 Thread Rahul
"profile" tells me that most of my runtime was spent in just one part (1.28 
sec cumulatively out of 1.29 secs. But what is "execfile"? I don't see this 
as a function call with my python code. Also what's the 0 in the snippet:  
":0(execfile)"? Isn't there supposed to be a line-number? 

Looking up "execfile" in the python manual leads me to "exec": "This 
statement supports dynamic execution of Python code."

But that seems pretty generic; how can I now try figuring out which part of 
my python file is the bottleneck? 

Sorry, I'm a newbiee to profiling.


##
   51651 function calls (37762 primitive calls) in 1.290 CPU seconds
 ncalls  tottime  percall  cumtime  percall filename:lineno(function)
[snip]
10.0100.0101.2801.280 :0(execfile)
[snip]
##




-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: cProfile.py not found.

2009-04-04 Thread Rahul
John Machin  wrote in news:4c8ee09e-71e2-464a-a3c0-
b630b4707...@c18g2000prh.googlegroups.com:

> Looks like our definitions of "read" differ :-)
> 

Sorry. I ought to have said "skimmed" :) 

I guess I am one of those guilty lazy-bums that the manual refers to under 
<<>>

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: cProfile.py not found.

2009-04-04 Thread Rahul
John Yeung  wrote in news:c0752f32-b0cf-4fde-
87a8-eb665252e...@k41g2000yqh.googlegroups.com:

> I believe cProfile was added in 2.5.  Your best bet on 2.4 is probably
> the profile module.  That is what the docs recommend.
> 

Thanks John. That works. I'll use "profile" instead.

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: cProfile.py not found.

2009-04-04 Thread Rahul
thon-which.noarch : Small which replacement that can be used as a 
Python module
python-wifi.noarch : Python binding for the wireless (wifi) extensions
python-xattr.i386 : Extended attributes for python
python-xdg.noarch : Python library to access freedesktop.org standards
python-xlib.i386 : Complete X11R6 client-side implementation
python-xlrd.noarch : Library to extract data from Microsoft Excel (tm) 
spreadsheet files
python-yadis.noarch : Relying party support for the Yadis service 
discovery protocol
python-yaml.noarch : Python package implementing YAML parser and emitter
python-yenc.i386 : yEnc Module for Python
python-zope-interface.i386 : Zope 3 Interface Infrastructure
pytone.i386 : Music Jukebox with a Curses Based GUI
pytraffic.i386 : Rush Hour game
pytz.noarch : World Timezone Definitions for Python
pywebdav.noarch : WebDAV library
pyxattr.i386 : Extended attributes library wrapper for Python
pyxdg.noarch : Python library to access freedesktop.org standards
pyxf86config.i386 : Python wrappers for libxf86config
pyzor.noarch : Pyzor collaborative spam filtering system
rdiff-backup.i386 : Convenient and transparent local/remote incremental 
mirror/backup
rhnlib.noarch : Python libraries for the RHN project
rhpl.i386 : Library of python code used by programs in Red Hat Linux
rhpxl.i386 : Python library for configuring and running X.
rpm-python.i386 : Python bindings for apps which will manipulate RPM 
packages.
rrdtool-python.i386 : Python RRDtool bindings
sagator.noarch : SAGATOR - antivir/antispam gateway for smtp server
scapy.noarch : Interactive packet manipulation tool and network scanner
scipy.i386 : Scipy: Scientific Tools for Python
scons.noarch : An Open Source software construction tool
sip.i386 : SIP - Python/C++ Bindings Generator
sip-devel.i386 : Files needed to generate Python bindings for any C++ 
class library
solarwolf.noarch : Python SDL game where you have to collect energy cubes
spacepong.noarch : An innovative Python SDL game that is controlled with 
the mouse
stgit.noarch : StGIT provides similar functionality to Quilt on top of 
GIT
sulk.i386 : Sulk, the hackable Space Hulk
supybot.noarch : Cross-platform IRC bot written in Python
swig.i386 : Simplified Wrapper and Interface Generator
sympy.noarch : A Python library for symbolic mathematics
system-config-bind.noarch : The Red Hat BIND DNS Configuration Tool.
tkinter.i386 : A graphical user interface for the Python scripting 
language.
trytond.noarch : Server for the Tryton application framework
txt2tags.noarch : Converts text files to HTML, XHTML, sgml, LaTeX, man...
wxPython.i386 : GUI toolkit for the Python programming language
wxPython-devel.i386 : Development files for wxPython add-on modules
yum-protect-packages.noarch : Yum plugin to prevents Yum from removing 
itself and other protected packages
zope.i386 : Web application server for flexible content management 
applications

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


cProfile.py not found.

2009-04-04 Thread Rahul
I need to profile a slow-running code. The problem is I cannot seem to find  
cProfile.py. 

Where can I get it? Is it not included in the normal distro? I tried 
googling it up and theres tons of info on how to use it but no links for 
where to download it from.

I am using Python 2.4.4 (#3, Feb 17 2008, 15:06:10). 

I am aware this is kind of dated but some of our legacy codes insist on 
using that exact version. 


-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: adodb has no attribute connect

2009-02-09 Thread Rahul
On Feb 10, 5:01 am, "Diez B. Roggisch"  wrote:
> Rahul schrieb:
>
> > Hello all,
>
> > I have to access data from database usingadodbso I did
>
> > Importadodb
> > Conn=adodb.NewADOConnection("odbc")
>
> > Upto this it works properly but when I say
>
> It does not. It returns None, thus the following error you see.
>
> > Conn.Connect("","","")
>
> > It gives error as
>
> > [Attributrerror]: Object Nonetype has no attribute Connect.
>
> > I have Red Hat Enterprise Linux 4
> > Python 2.5
> > Mod_python 3.3.1
>
> According to the docs on the (very old and seemingly not actively
> developedadodb-site), "odbc" needs the Python windows extensions. As
> you are on redheat, I have difficulties believing you make these work.
>
> Maybe mxodbc works? Or even better, ditch that ado-stuff and connect
> directly to your database. Python's DB-API is better I guess, no need
> for this attempt at mimicking windows APIs.
>
> Diez

Thank you Diez

I think this is very useful for me to change my mind and get shifted
to DB-API.

I will try to work on it.

Rahul
--
http://mail.python.org/mailman/listinfo/python-list


adodb has no attribute connect

2009-02-08 Thread Rahul
Hello all,

I have to access data from database using adodb so I did

Import adodb
Conn=adodb.NewADOConnection("odbc")

Upto this it works properly but when I say

Conn.Connect("","","")

It gives error as

[Attributrerror]: Object Nonetype has no attribute Connect.

I have Red Hat Enterprise Linux 4
Python 2.5
Mod_python 3.3.1

The same is also not working from python console

Please guide me through this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: i have an query regarding pyodbc

2009-02-06 Thread Rahul
On Feb 6, 3:53 pm, Rahul  wrote:
> On Feb 6, 11:27 am, Rahul  wrote:
>
>
>
> > hello all,
>
> > I have installed pyodbc on my red hat enterprise 4 linux machine but
> > when i go to use that using statement,
>
> > import pyodbc
>
> > through python console it gives me error as
>
> > ImportError : dynamic module does not define init function
> > (initpyodbc)
>
> > and when i do 'nm pyodbc.so' command i get output as
>
> > [r...@dbserver site-packages]# nm pyodbc.so 1600 A __bss_start
> > 03ec t call_gmon_start 1600 b completed.1 14fc d
> > __CTOR_END__
> > 14f8 d __CTOR_LIST__
> >          w __cxa_finalize@@GLIBC_2.1.3
> > 04a8 t __do_global_ctors_aux
> > 0410 t __do_global_dtors_aux
> > 15f8 d __dso_handle
> > 1504 d __DTOR_END__
> > 1500 d __DTOR_LIST__
> > 150c A _DYNAMIC
> > 1600 A _edata
> > 1604 A _end
> > 04d8 T _fini
> > 046c t frame_dummy
> > 04f4 r __FRAME_END__
> > 15e8 A _GLOBAL_OFFSET_TABLE_
> >          w __gmon_start__
> > 03b4 T _init
> > 1508 d __JCR_END__
> > 1508 d __JCR_LIST__
> >          w _Jv_RegisterClasses
> > 15fc d p.0
>
> > which means there is no init function.
>
> > So what might be the cause for that?
>
> > I have build that pyodbc twice.
> > Any help regarding this will be greatly appreciated.
>
> > Thanks & Regards
> > Rahul
>
> this problem was due to not proper building of pyodbc

Now my problem was,
i have two versions of python installed at different locations but
when i use import statement from psp pages
it displays the error as
ImportError : dynamic module does not define init function(initpyodbc)

this error was due to pointing to older version of python.

So, i want to know how to point my import statements to the new
version of python.

Thanks & regards
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: i have an query regarding pyodbc

2009-02-06 Thread Rahul
On Feb 6, 11:27 am, Rahul  wrote:
> hello all,
>
> I have installed pyodbc on my red hat enterprise 4 linux machine but
> when i go to use that using statement,
>
> import pyodbc
>
> through python console it gives me error as
>
> ImportError : dynamic module does not define init function
> (initpyodbc)
>
> and when i do 'nm pyodbc.so' command i get output as
>
> [r...@dbserver site-packages]# nm pyodbc.so 1600 A __bss_start
> 03ec t call_gmon_start 1600 b completed.1 14fc d
> __CTOR_END__
> 14f8 d __CTOR_LIST__
>          w __cxa_finalize@@GLIBC_2.1.3
> 04a8 t __do_global_ctors_aux
> 0410 t __do_global_dtors_aux
> 15f8 d __dso_handle
> 1504 d __DTOR_END__
> 1500 d __DTOR_LIST__
> 150c A _DYNAMIC
> 1600 A _edata
> 1604 A _end
> 04d8 T _fini
> 046c t frame_dummy
> 04f4 r __FRAME_END__
> 15e8 A _GLOBAL_OFFSET_TABLE_
>          w __gmon_start__
> 03b4 T _init
> 1508 d __JCR_END__
> 1508 d __JCR_LIST__
>          w _Jv_RegisterClasses
> 15fc d p.0
>
> which means there is no init function.
>
> So what might be the cause for that?
>
> I have build that pyodbc twice.
> Any help regarding this will be greatly appreciated.
>
> Thanks & Regards
> Rahul

this problem was due to not proper building of pyodbc
--
http://mail.python.org/mailman/listinfo/python-list


i have an query regarding pyodbc

2009-02-05 Thread Rahul
hello all,

I have installed pyodbc on my red hat enterprise 4 linux machine but
when i go to use that using statement,

import pyodbc

through python console it gives me error as

ImportError : dynamic module does not define init function
(initpyodbc)

and when i do 'nm pyodbc.so' command i get output as

[r...@dbserver site-packages]# nm pyodbc.so 1600 A __bss_start
03ec t call_gmon_start 1600 b completed.1 14fc d
__CTOR_END__
14f8 d __CTOR_LIST__
 w __cxa_finalize@@GLIBC_2.1.3
04a8 t __do_global_ctors_aux
0410 t __do_global_dtors_aux
15f8 d __dso_handle
1504 d __DTOR_END__
1500 d __DTOR_LIST__
150c A _DYNAMIC
1600 A _edata
1604 A _end
04d8 T _fini
046c t frame_dummy
04f4 r __FRAME_END__
15e8 A _GLOBAL_OFFSET_TABLE_
 w __gmon_start__
03b4 T _init
1508 d __JCR_END__
1508 d __JCR_LIST__
 w _Jv_RegisterClasses
15fc d p.0


which means there is no init function.

So what might be the cause for that?

I have build that pyodbc twice.
Any help regarding this will be greatly appreciated.

Thanks & Regards
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Insatlling python on compute-node-linux (Cray).

2008-12-15 Thread Rahul
Has anyone tried installing Python on Compute Node Linux (on a cray)? I was 
having trouble getting it running. I see that CNL does not support dynamic 
libraries but I am not sure what the best way then is to get Python 
running.

Any tips?

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Python 3000 C API Changes

2008-08-23 Thread rahul
I am trying to find out what Python C APIs are changing from Python
2.5 to Python 3.0 but there does not seem to be a single list of
changes (or at least google is not finding one).
If someone knows about where I should look, please let me know.
--
http://mail.python.org/mailman/listinfo/python-list


yum installs Tkinter in a way visible to only one python installation

2008-05-29 Thread Rahul
My RHEL yum package-manager comes with  Python-2.4.3. We also have a 
seperate Python-2.4.4 Installation on our box.

When I added Tkinter using 'yum install tkinter' it seems to have added it 
in a manner that it is exclusively visible to Python-2.4.3. I cannot import 
Tkinter from Python-2.4.4. 

What's the best way to work around this? 

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


adding tkinter support on an existing python installation

2008-05-28 Thread Rahul
'import _tkinter'  fails on my system. I wanted to enable tk support. I do 
have tk and tk-devel installed (but they weren't around when we installed 
python). What's the best way to get these modules into python? I hope I do 
not have to reinstall python itself? Or do I?

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: python command mis-interprets arrow keys

2008-04-29 Thread Rahul
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in news:67pq47F2plmb8U1
@mid.uni-berlin.de:

> 
> The question is if python is build with readline support. Did the python 
> version work before, and somehow got messed up, or did you build it 
> yourself and it never actually worked? 

I suspect we upgraded our RHEL and that broke it. Has never worked after.

Is there a way to extract what cmd-line options my python was compiled with? 
Might be worth it before I go the long-painful route of re-installing.


-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Re: python command mis-interprets arrow keys

2008-04-29 Thread Rahul
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> 
> Is libreadline installed?

Thanks for your help Diez. I did a locate and found:

/usr/lib/libreadline.a
/usr/lib/libreadline.so
/usr/lib/libreadline.so.5
/usr/lib/libreadline.so.5.1
/usr/local/src/Python-2.4.4/Doc/lib/libreadline.tex

Any better way to check?

-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


python command mis-interprets arrow keys

2008-04-29 Thread Rahul
My python command line seems messed up. I can't seem to be able to use my 
backspace key nor my arrow keys. 

I only get control characters: ^[[A^[[D^[[D^[[D^[[C^[[C^[[C etc.

I access my Linux box via  a SecureCRT console. Only after opening the 
python interpreter does this occur. Linux command like is OK. vim 
interprets keystrokes correctly. So do other interpreters e.g. gnuplot.

$LANG $TERM 
en_US xterm-color

Versions:
Python 2.4.4 
GCC 4.1.2 20070925 (Red Hat 4.1.2-33)


Any sugesstions? Google did not throw anything relevant. 


-- 
Rahul
--
http://mail.python.org/mailman/listinfo/python-list


Python Developer, DIRECT CLIENT REQUIREMENT: Please Respond

2008-04-21 Thread Rahul Ka

 Hi ,

We have this urgent DIRECT client requirement . Please let me know if
you have suitable candidates. Please send me their resume rate and
contact details ASAP.

TITLE: Python Developer
LOCATION: Silver spring, MD
DUARTION:6 Months +


JOB REQUIREMENTS
Strong C++ and Python experience
5 to 7 years of UNIX experience
5 to 7 years of TCP/IP network development experience
3 to 5 years of Oracle DB experience- Good to have
Payment industry knowledge a plus


With Warm Regards and Wishes !

RAHUL
Marketing Executive
AMPLIFY SYSTEMS
E Mail:[EMAIL PROTECTED]
Phone :603-791-4428
Fax   :267-284-6042

-- 
http://mail.python.org/mailman/listinfo/python-list


importing a csv file as a Numeric array

2008-03-25 Thread Rahul
What's  a good way of importing a csv text file of floats into a
Numeric array? I tried the csv module and it seems to work well so
long as I've ints. Does anyone have any suggestions / snippets that
work to import a csv file of floats into a Numeric array?

-Rahul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Rahul
Hi.
Instead of listing the difference ..here are some things that are
COMMON to both common lisp and python :

1.Dynamic typing.
2.garbage collection
3.powerful data structures
4.good object systems. (here people from lisp usually claim that clos
is the most powerful object system...but i think python and lisp are
comparable with none of them being better than the other. they are
different than each other. and i consider clos without mop to be
inferior. mop stands for meta object protocol...a thing which hasnt
been specified in the ansi lisp standard but is provided by most
implementations)
5.functions and types as first class objects
6.interactive development.

The differences:

1.Macros : Macros are extremely powerful and a double edges sword. Dont
believe anyone (whether they praise them or abhor them). Go and learn
them and decide for yourself.

2.Readability : Python is generally believed to be far more readable
than ANY other language. (Lisp isnt particularly unreadable).

The only way to really find out which is better is to learn both and
decide yourself.

i personally like python , lisp and c. now c evokes derision from both
python and lisp folks sometimes and thats incorrect too.
rahul

[EMAIL PROTECTED] wrote:
> I've been reading the beloved Paul Graham's "Hackers and Painters".
> He claims he developed a web app at light speed using Lisp and lots
> of macros.
>
> It got me curious if Lisp
> is inherently faster to develop complex apps in.  It would seem if you
> could create your own language in Lisp using macros that that would be
> quite an advantage
>
> I realize that Python has operator overloading and OOP so I'm not sure.
>
> Any ideas?  Any *evidence* one way or another?
> 
> thanks!
> 
> Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange __call__

2005-06-29 Thread Rahul
Hi.
I understood your point.
thanks...
rahul
Steven Bethard wrote:
> Steven Bethard wrote:
> >
> > def wrap(obj):
> >  def f(*args, **kwargs):
> >  for arg in args:
> >  print arg
> >  return obj(*args, **kwargs)
> >  return f
> >
> > @wrap
> > def func(a, b, c):
> >  ...
> >
> > class C(object):
> >  ...
> > C = wrap(C)
>
> Rahul top-posted:
>  > If you do C = wrap(C) C no longer remains a class..it becomes a
>  > function.
>
> And if you do
>  func = wrap(func)
> which is the equivalent of
>  @wrap
>  def func(...):
>  ...
> then func no longer has the same signature.  But as Reinhold suggests,
> does that really matter?  In the case of the class, you can still call
> it to create class instances.  In the case of the function, you can
> still call it to retrieve return values.  Why do you care about the type
> of the object?
>
> In the case that it does matter, e.g. you want to be able to invoke your
> methods from the class instead of the instance, you can wrap the
> specific function that you need wrapped, e.g.
>
> class C(object):
>  @wrap
>  def __new__(cls, *args):
>  super(C, cls).__new__(cls, *args)
>  ...
> 
> STeVe

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange __call__

2005-06-29 Thread Rahul
If you do C = wrap(C) C no longer remains a class..it becomes a
function.

Steven Bethard wrote:
> Rahul wrote:
> > def wrapper(obj):
> >g = obj.__call__
> >def f(*args,**kwargs):
> >  for arg in args:print arg
> >  return g(*args,**kwargs)
> >obj.__call__=f
> > but it seems this will not work for functions :(
>
> def wrap(obj):
>  def f(*args, **kwargs):
>  for arg in args:
>  print arg
>  return obj(*args, **kwargs)
>  return f
>
> @wrap
> def func(a, b, c):
>  ...
> 
> class C(object):
>  ...
> C = wrap(C)
> 
> STeVe

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange __call__

2005-06-29 Thread Rahul
Hi.
well if you do dir(a) just after defining 'a' then it does show
'__call__'.
the reason i wanted to do it is that i wanted to see if theres a
uniform way to  wrap a function and callable objects so that for
example i can get some message printed whenever a function or a
function-like-object is called. then i could simply do :

def wrapper(obj):
   g = obj.__call__
   def f(*args,**kwargs):
 for arg in args:print arg
 return g(*args,**kwargs)
   obj.__call__=f
but it seems this will not work for functions :(


Andreas Kostyrka wrote:
> Just a guess, but setting "__X__" special methods won't work in most cases
> because these are usually optimized when the class is created.
>
> It might work if a.__call__ did exist before (because class a: contained
> a __call__ definition).
>
> Andreas
>
> On Wed, Jun 29, 2005 at 09:15:45AM +0100, Michael Hoffman wrote:
> > Rahul wrote:
> > > Consider the following:
> > > def a(x):
> > >  return x+1
> > >
> > > def b(f):
> > >   def g(*args,**kwargs):
> > > for arg in args:
> > > print arg
> > > return f(*args,**kwargs)
> > >   return g
> > >
> > > a.__call__ = b(a.__call__)
> > >
> > > now calling a(1) and a.__call__(1) yield 2 different results!!
> > > i.e. for functions a(1) doesnt seem to be translated to a.__call__ if
> > > you assign a new value to a.__call__?
> >
> > I don't know why this happens, but setting the __call__ attribute of a
> > is a pretty strange thing to do. Why not just set a instead? The
> > original function a(x) will still be stored as a closure in what is
> > returned from b().
> >
> > If this is of purely academic interest then the answer is I don't know. :)
> > --
> > Michael Hoffman
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


strange __call__

2005-06-28 Thread Rahul
Consider the following:
def a(x):
 return x+1

def b(f):
  def g(*args,**kwargs):
for arg in args:
print arg
return f(*args,**kwargs)
  return g

a.__call__ = b(a.__call__)

now calling a(1) and a.__call__(1) yield 2 different results!!
i.e. for functions a(1) doesnt seem to be translated to a.__call__ if
you assign a new value to a.__call__?
i am using python 2.3.3 
somebody please clear this confusion

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple instances of a python program

2005-06-17 Thread Rahul
Steven D'Aprano wrote:
> On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote:
>
> > Hi.
> > I am part of a group in my univ where we organize a programming
> > contest. In this contest we have a UDP based server. The server
> > simulates a game and each contestant is to develop a team of virtual
> > players. Each team is composed of 75 similar bots...i.e. governed by
> > the same logic. Thus the contestant submits a single copy of the client
> > and we instantiate the same program 75 times at the same time.
> > The problem is that while executables from C source files are small and
> > we can make 75 processes but we dont know what to do with python.
> >
> > If you have a python script and you want that 75 copies of the script
> > be run simultaneously how will you do it? Is there anyway to do so
> > without running 75 copies of the python interpreter simultaneously?
>
> Have you actually tested the performance of 75 instances of Python
> running? Do you know that it will be too slow for your server, or are you
> trying to optimize before testing?
>
> I wrote a short Python script, then launched 115 instances of Python
> executing the script. There was no detectable slowdown of my system, which
> is far from a high-end PC.
>
> The details of the script aren't important. It may even be that what I
> tested is not even close to the load your server needs to deal with. But
> you may be surprised at just how easily even a low-end PC copes 75
> instances of Python. Or perhaps not -- but the only way to tell is to try.

Well...i havent tried (yes i hear "Premature optimization is evil evil
evil i say") but the point was that if we can find a solution consuming
less memory than we can even increase the number from 75 to lets say
200. as for hardware we have machines with 1.7 Ghz P4 and 128 mb ram.
and i cant run them right now...since i am currently not in my
univ...but asked now since we are planning right now and wanted to see
which languages we can support. Probably c,c++,python and lisp using
clisp...and java if we can find a way to avoid running 75 jvms...this
year we supported c,c++,java and actually ran 75 jvms using 3 machines
and it was horrible so we are looking for better ways for the 2006
contest. And we may port our server from java to python too but it
seems not many people had python installed but most had java installed.

rahul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple instances of a python program

2005-06-17 Thread Rahul
Hi.
I will look into it..thanks
rahul

Jeremy Sanders wrote:
> On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote:
>
> > If you have a python script and you want that 75 copies of the script be
> > run simultaneously how will you do it? Is there anyway to do so without
> > running 75 copies of the python interpreter simultaneously?
>
> If you're running on Linux (and other Unixes perhaps), you could use the
> os.fork() function to create independent child processes from a single
> python process. I believe Linux forked processes share memory until a
> section of memory is written to (copy on write functionality).
>
> If most of python is in a shared library, then this probably won't make
> much difference.
> 
> Jeremy

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple instances of a python program

2005-06-17 Thread Rahul
Daniel Dittmar wrote:
> Rahul wrote:
> > Hi.
> > I am part of a group in my univ where we organize a programming
> > contest. In this contest we have a UDP based server. The server
> > simulates a game and each contestant is to develop a team of virtual
> > players. Each team is composed of 75 similar bots...i.e. governed by
> > the same logic. Thus the contestant submits a single copy of the client
> > and we instantiate the same program 75 times at the same time.
> > The problem is that while executables from C source files are small and
> > we can make 75 processes but we dont know what to do with python.
> >
> > If you have a python script and you want that 75 copies of the script
> > be run simultaneously how will you do it? Is there anyway to do so
> > without running 75 copies of the python interpreter simultaneously?
> >
>
> The technical way would be to use threads.
>
> Of course it could be that the rules of the game explicitly forbid that
> bots of a group communicate other than through the server. And it is
> easier to cheat there when you have only one Python program running.

yup...its not allowed to communicate through other means.

well we do realise that its not easy to catch cheating but we require
the source code of the participants too. and we dont want to provide
simple loopholes.

rahul

-- 
http://mail.python.org/mailman/listinfo/python-list


Multiple instances of a python program

2005-06-16 Thread Rahul
Hi.
I am part of a group in my univ where we organize a programming
contest. In this contest we have a UDP based server. The server
simulates a game and each contestant is to develop a team of virtual
players. Each team is composed of 75 similar bots...i.e. governed by
the same logic. Thus the contestant submits a single copy of the client
and we instantiate the same program 75 times at the same time.
The problem is that while executables from C source files are small and
we can make 75 processes but we dont know what to do with python.

If you have a python script and you want that 75 copies of the script
be run simultaneously how will you do it? Is there anyway to do so
without running 75 copies of the python interpreter simultaneously?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: computer algebra packages

2005-06-08 Thread Rahul

Hi.
The reason is simple enough. I plan to do some academic research
related to computer algebra for which i need some package which i can
call as a library. Since i am not going to use the package
myself..(rather my program will)..it will be helpful to have a python
package since i wanted to write the thing in python. if none is
available then probably i will need to work on an interface to some
package written in some other language or work in that language itself.
rahul
Kay Schluehr wrote:
> Rahul wrote:
> > Hi.
> > Well is there an open source computer algebra system written in python
> > or at least having a python interface?
> > I know of 2 efforts: pythonica and pyginac...are there any others?
> >
> > rahul
>
> Not in the moment. But I have a question to you: why do you seek for a
> CAS in Python? I ask this because I'm interested in such kind of stuff
> and secretly working on one, but this is highly experimental, a proof
> of the concept work and will probably not provide the amount of
> features/packages of a commercial CAS like Mathematica and Maple in a
> dozend years. There are also a couple of free CAS like Octave or Yacas,
> that do their job. Why do people ask periodically for a CAS in Python
> in this place? I'm just curious about it.
> 
> Kay

-- 
http://mail.python.org/mailman/listinfo/python-list


computer algebra packages

2005-06-07 Thread Rahul
Hi.
Well is there an open source computer algebra system written in python
or at least having a python interface?
I know of 2 efforts: pythonica and pyginac...are there any others?

rahul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optional Static Typing

2004-12-25 Thread Rahul
I am assuming that optional type checking is being added for easier
debugging only. So if 'expects' are turned on , python raises
warnings(which do not halt the system) but not when they are turned
off. These will enable easier debugging for new people while not
affecting masters. Also,perhaps, it will be easier to accomodate till
type checking mechanism is perfected(if it is implemented at all that
is) so that python does not stop you when it is in fact  python which
might be making some mistake.(This last statement is a guess only...)

It is similar to assert and __debug__=1 in a way.

So the crux is :
1.Expects is only a bridge between type checking and dynamic typing.
2.Type checking is done only as a tool which you are free to override
if you want to.
3.The objective of type checking here is only to make debugging easier
and not speed/optimization.
4.The point is not that 'expects' be a additional keyword.You can go
like this also :
def (int a,int b): or whatever you like. Only that expects make it a
bit clearer IMHO.

sincerely.,
rahul

Scott David Daniels wrote:
> Rahul wrote:
> > 1.def gcd(a,b) expects (int,int)
>
> I presume by this syntax you mean something like:
>  def gcd(a, b) expects (int, int):
>  if b > a:
>  a, b = b, a
>  while a > b > 0:
>  a, b = b, a % b
>  return a
>
> > Here the function is not enforcing type checking. The compiler
should
> > only generate warning when someone passes something which is not an
int
> > and should not generate an error.Maybe the person calling the
function
> > knows what he is doing and wants to pass the unexpected type.
>
> But if this is the case, why is it different from?:
>  def gcd(a, b): # expects (int, int)
>  return a * b
>
> > 2.Another possibility is to let the function decide if the type is
not
> > what it is expecting. Maybe the function recvs some kind of flag
which
> > tells it that the type passed is not what it was expecting. So it
can
> > throw an error if it is really critical.
>
> Again, why make the test at all if you don't want to act on it?
>   assert  aborts if it is checked at all, but with __debug__
> defined as 1, it passes.  Perhaps you are proposing that expects be
> used in that context.
>
> > 3.In my post i am not stressing on adding 'expects' as keyword or
> > something. Only that type should not be enforced and 'expects'
makes
> > this clear.
> You need to explain why anyone would want to write expects at all.
> If you are expecting the code generation to change, you'd better
> enforce, rather than advise, unless you are defining points at which
> to do code specialization on types.
> 
> --Scott David Daniels
> [EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optional Static Typing

2004-12-24 Thread Rahul
Hi.
Well i am a newbie to python and maybe not qualified enough to make a
comment on proposals to changes in python. My previous programming
experience has been in Java and C. So maybe you will forgive me if i
make any outlandish comments.

But anyway here goes:

I think instead what should be done is:

1.def gcd(a,b) expects (int,int)

Here the function is not enforcing type checking. The compiler should
only generate warning when someone passes something which is not an int
and should not generate an error.Maybe the person calling the function
knows what he is doing and wants to pass the unexpected type.

2.Another possibility is to let the function decide if the type is not
what it is expecting. Maybe the function recvs some kind of flag which
tells it that the type passed is not what it was expecting. So it can
throw an error if it is really critical.

3.In my post i am not stressing on adding 'expects' as keyword or
something. Only that type should not be enforced and 'expects' makes
this clear.

Rahul Garg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dot products

2004-12-19 Thread Rahul

Raymond Hettinger wrote:
> [Rahul].
> > I want to compute dot product of two vectors stored as lists a and
b.a
> > and b are of the same length.
> >
> > one simple way is
> > sum(a[i]*b[i] for i in range(len(a)))
> >
> > another simple way is
> > ans=0.0
> > for i in range(len(a)):
> > ans=ans+a[i]*b[i]
> >
> > But is there any other way which is faster than any of the above.
>
> Yes:
>  from itertools import imap
>  from operator import mul
>  ans = sum(imap(mul, a, b))
>
> In general:
> * reduction functions like sum() do not need their arguments to
>take time building a full list; instead, an iterator will do fine
> * applying itertools instead of genexps can save the eval-loop
overhead
> * however, genexps are usually more readable than itertools solutions
> * xrange() typically beats range()
> * but indexing is rarely the way to go
> * izip() typically beats zip()
> * imap() can preclude the need for either izip() or zip()
> * the timeit module settles these questions quickly
>
> Here are the some timings for vectors of length 10 and 3 respectively
>
> C:\pydev>python timedot.py 3
> 1.2510984 sum(a[i]*b[i] for i in xrange(len(a)))
> 1.16825625639 sum(x*y for x,y in izip(a,b))
> 1.45373455807 sum(x*y for x,y in zip(a,b))
> 0.635497577901 sum(imap(mul, a, b))
> 0.85894416601 sum(map(mul, a, b))
>
> C:\pydev>python timedot.py 10
> 2.19490353509 sum(a[i]*b[i] for i in xrange(len(a)))
> 2.01773998894 sum(x*y for x,y in izip(a,b))
> 2.44932533231 sum(x*y for x,y in zip(a,b))
> 1.24698871922 sum(imap(mul, a, b))
> 1.49768685362 sum(map(mul, a, b))
>
>
>
> Raymond Hettinger
Thanks all of you guys for enlightening me. Python is truly elegant.

-- 
http://mail.python.org/mailman/listinfo/python-list


dot products

2004-12-19 Thread Rahul
HI.
I want to compute dot product of two vectors stored as lists a and b.a
and b are of the same length.

one simple way is
sum(a[i]*b[i] for i in range(len(a)))

another simple way is
ans=0.0
for i in range(len(a)):
ans=ans+a[i]*b[i]

But is there any other way which is faster than any of the above. (By
the way profiling them i found that the second is faster by about 30%.)
rahul

-- 
http://mail.python.org/mailman/listinfo/python-list


why not arrays?

2004-12-16 Thread Rahul
Hi.
I just wanted to know why arrays have not been included as a builtin
datatype like lists or dictionaries? The numpy extension shows that it
can be implemented. then why not include arrays in core python?
rahul

-- 
http://mail.python.org/mailman/listinfo/python-list