Re: Need to import stuff
Hi, Used imp. It worked. Thanks Daniel Kluev wrote: On Wed, Aug 18, 2010 at 9:40 AM, abhijeet thatte mailto:[email protected]>> wrote: Hi, Thanks for the reply. But I guess it does not support nested file paths. If user gives 'abcd' then I need to import "//*Do/Stuff/abcd*/". Out of which only /"abcd" is taken run time. Do and Stuff are fixed. / /I got an error "/ImportError: Import by filename is not supported.". Any solution?? For complex importing, you can use imp module, http://docs.python.org/library/imp.html Like this: module_desc = imp.find_module(name, [base_path]) module = imp.load_module(full_name, *module_desc) -- With best regards, Daniel Kluev -- http://mail.python.org/mailman/listinfo/python-list
Question on Socket Timeouts
Hi all, I'm new to network programming. I have a question. Can we set a timeout to limit how long a particular socket can read or write? I have used a settimeout() function. The settimeout() works fine as long as the client doesnt send any data for x seconds. The data that I receive in the server after accept()ing a connect() from a client I check if the client is sending any invalid data. I'm trying to ensure that a client sending invalid data constantly cannot hold the server. So is there a way of saying I want the client to use this socket for x seconds before I close it, no matter what data I receive? Thanks in advance, -Abhijeet -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Socket Timeouts
I also tried looking at SO_RCVTIMEO option. Turns out that also resets if data is received. And yeah I implemented that as a separate logic in my code. I was wondering if sockets natively provided this functionality. Thanks again for clarifying. Cheers, Abhijeet On Mon, Nov 19, 2012 at 12:40 AM, Cameron Simpson wrote: > On 18Nov2012 03:27, Abhijeet Mahagaonkar wrote: > | I'm new to network programming. > | I have a question. > | > | Can we set a timeout to limit how long a particular socket can read or > | write? > > On the socket itself? Probably not. But... > > | I have used a settimeout() function. > | The settimeout() works fine as long as the client doesnt send any data > for > | x seconds. > | The data that I receive in the server after accept()ing a connect() from > a > | client I check if the client is sending any invalid data. > | I'm trying to ensure that a client sending invalid data constantly cannot > | hold the server. So is there a way of saying I want the client to use > this > | socket for x seconds before I close it, no matter what data I receive? > > Not the time you set up the socket, or when you accept the client's > connection. Thereafter, ever time you get some data, look at the clock. > If enough time has elapsed, close the socket yourself. > > So, not via an interface to the socket but as logic in your own code. > > Cheers, > -- > Cameron Simpson > > Their are thre mistakes in this sentence. > - Rob Ray DoD#3 > -- http://mail.python.org/mailman/listinfo/python-list
Issue with Scrapping Data from a webpage- Noob Question
Hi Fellow Pythoners,
I'm trying to collect table data from an authenticated webpage (Tool) to
which I have access.
I will have the required data after 'click'ing a submit button on the tool
homepage.
When I inspect the submit button i see
Thus the tool's homepage is of the form www.example.com/Tool and on
clicking the submit button the data I need will be at
www.example.com/Tool/index.do
The problem that I'm running into is in my below code is giving me the
source of homepage(www.example.com/Tool) and not the of the submitted page(
www.example.com/Tool/index.do)
url="www.example.com/Tool/index.do"
request = urllib2.Request(url, data, {'Authorization': "Basic " +
base64.b64encode("%s:%s" % (username, password))})
Response_Page=urllib2.urlopen(request).read()
Is there a way I can access the source of the submitted page?
PS: Sorry for laying out very tiny details on what I'm trying to do, I just
wanted to explain myself clearly :)
Thanks in advance for your time on this one.
Warm Regards,
Abhi
--
http://mail.python.org/mailman/listinfo/python-list
Running a Python script on a web server
Dear Pythoners, I have written a few python tools and cant distribute as exe due to scalability issues. I started with a few tools and gave it as exe to the users and now as the number of tools have increased, they complain they have too many exes :) So i have requested a server space so I need some inputs on how i will be able to "host" these scripts on a webserver and have them run on browsers rather than on individual systems. I have not done web prog, so consider this as a noob question :) Thanks in advance Warm Regards, Abhijeet -- http://mail.python.org/mailman/listinfo/python-list
Re: Running a Python script on a web server
>>Python doesn't normally run in a web browser. There's two easy options: Is there an option of running it like php? I have never written in php, but my understanding is that the php script will be saved in some remote server and we will be able to run it using the url. pls correct me if i;m wrong. So i thought is there a python way of doing something like this? On Wed, Jun 8, 2011 at 9:34 AM, Chris Angelico wrote: > On Wed, Jun 8, 2011 at 1:10 PM, Abhijeet Mahagaonkar > wrote: > > So i have requested a server space so I need some inputs on how i will be > > able to "host" these scripts on a webserver and have them run on browsers > > rather than on individual systems. > > Python doesn't normally run in a web browser. There's two easy options: > > 1) Use very simple web hosting that lets people download scripts and > run them. Anything can do this, but all you gain is that they don't > have to keep a collection of scripts / EXEs on their hard drives. > > 2) Run the Python scripts on the web server. I don't know whether this > is even possible in your situation; it would turn them into quite > different tools. > > I have no experience with it, but Jython can make applets. Again, > though, these would be quite different tools from simple Python > scripts. Web browsers aren't generally happy for in-browser scripts > to, for instance, read and write files on the user's hard drive. > > I think you're ultimately going to need to keep on distributing those > scripts. But if you get your users to install a Python interpreter, > they need only install it once and then you can distribute all your > scripts in .py format rather than py2exeing them all. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Running a Python script on a web server
I guess i got my answer :) Thanks Regards, Abhijeet On Wed, Jun 8, 2011 at 12:01 PM, D'Arcy J.M. Cain wrote: > On Wed, 8 Jun 2011 11:22:53 +0530 > Abhijeet Mahagaonkar wrote: > > >>Python doesn't normally run in a web browser. There's two easy options: > > > > Is there an option of running it like php? I have never written in php, > but > > my understanding is that the php script will be saved in some remote > server > > and we will be able to run it using the url. > > pls correct me if i;m wrong. > > Well, not wrong but perhaps not phrasing your original question > correctly. > > > > On Wed, Jun 8, 2011 at 1:10 PM, Abhijeet Mahagaonkar > > > wrote: > > > > So i have requested a server space so I need some inputs on how i > will be > > > > able to "host" these scripts on a webserver and have them run on > browsers > > > > rather than on individual systems. > > That's the normal way to run Python on the web. You store your Python > (or Perl or PHP or compiled C) programs on a web server that offers > Python http://www.Vex.Net/ and when someone > clicks on the link the server runs them and presents the results. This > is different than something like Java or Javascript that runs in the > browser. > > If that still doesn't answer your question then perhaps you can try to > clarify exactly what it is you are trying to do. > > -- > D'Arcy J.M. Cain | Democracy is three wolves > http://www.druid.net/darcy/| and a sheep voting on > +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. > -- http://mail.python.org/mailman/listinfo/python-list
Re: (Maybe off topic) Can someone explain what a finite state machine is?
You might wanna have a look at theory of computation. http://www.youtube.com/user/Coderisland#g/c/601FC994BDD963E4 in this lecture series you will have an explanation for FSM from the ground up -AB On Tue, Jul 19, 2011 at 7:02 PM, Matty Sarro wrote: > Hey everyone. I am currently reading through an RFC, and it mentions > that a client and server half of a transaction are embodied by finite > state machines. I am reading through the wikipedia article for finite > state machines, and sadly it's going a bit above my head. I don't > really have a background in engineering, and would really love to > understand what is being said. Does anyone have a simple way to > explain it? > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Tips on Speeding up Python Execution
Dear Pythoners, I have written a python application which authenticates a user, reads a webpage and searches for pattern and builds a database ( In my case its a dictinary with fixed set of keys). Inputting the username and password for authentication and final display of the results is done by GUI. I was able to isolate that major chunk of run time is eaten up in opening a webpages, reading from them and extracting text. I wanted to know if there is a way to concurrently calling the functions. here is my pseudo code: database=[] in a while loop: build the url by concatenating the query parametres temp=urlopen(url).read() dict['Key1']=get_key1_data(temp) ## passing the entire string obtained by .read() dict['key2']=get_key2_data(temp) . . . dict['keyn']=get_keyn_data(temp) database=database+[dict] ## building an array of dictionaries My question here is can I have the functions get_key1_data to get_keyn_data run in some concurrent way.?? I ask this because these functions are not dependent on one another. They all have access to the same parsed url and independently pull data in order to populate the final database Appreciating your help in this one. Warm Regards, Abhijeet. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tips on Speeding up Python Execution
Thats awesome. Its time I migrate to 3 :) On Fri, Apr 8, 2011 at 11:29 PM, Raymond Hettinger wrote: > On Apr 8, 12:25 am, Chris Angelico wrote: > > On Fri, Apr 8, 2011 at 5:04 PM, Abhijeet Mahagaonkar > > > > wrote: > > > I was able to isolate that major chunk of run time is eaten up in > opening a > > > webpages, reading from them and extracting text. > > > I wanted to know if there is a way to concurrently calling the > functions. > > > > So, to clarify: you have code that's loading lots of separate pages, > > and the time is spent waiting for the internet? If you're saturating > > your connection, then this won't help, but if they're all small pages > > and they're coming over the internet, then yes, you certainly CAN > > fetch them concurrently. As the Perl folks say, There's More Than One > > Way To Do It; one is to spawn a thread for each request, then collect > > up all the results at the end. Look up the 'threading' module for > > details: > > > > http://docs.python.org/library/threading.html > > The docs for Python3.2 have a nice example for downloading multiple > webpages in parallel: > > > http://docs.python.org/py3k/library/concurrent.futures.html#threadpoolexecutor-example > > Raymond > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there anyway to use urllib2 to download a file from http server?
I guess urlretrieve() would do the job -AB On Sat, Sep 10, 2011 at 9:11 PM, crow wrote: > As the title. > > Or is there other module that can handle this task? > > Many thanks in advance > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Help With Tkinter.Checkbutton Widget
Dear Pythoners,
I have a list of dictionaries. Here i have a variable which should gather
input from Checkbutton widget in Tkinter. The Problem that I'm facing is
that I'm unable to set or reset the key in every dictionary using the
checkbutton widget.
Here is what i have been doing.
list_of_dict=[{'Flag':0},{'Flag':0}, {'Flag':0}]
root=Tkinter.Tk()
while i<3:
q=Tkinter.IntVar()
w=Tkinter.Checkbutton(root, text='Need to include this value?',
onvalue=1, offvalue=0, variable=q)
w.grid(row=i)
list_of_dict[i]['Flag']=q.get()
root.mainloop()
Could you please let me know what I'm doing wrong?
I have tried multiple ways of accomplishing this for eg. by having a command
option which will just toggle the
list_of_dict[i]['Flag']=not(list[i]['Flag'])
Please let me know the best way of doing this.
Thanks in advance :)
Warm Regards,
Abhijeet.
--
http://mail.python.org/mailman/listinfo/python-list
Need to parse python dictionaries into xml
Hello,
I am a novice Python user. I am using Python to parse some hardware
specifications and create xml files from them.
I generate dict of really huge sizes. (I am parsing some 10,000 register
definitions.)
So, it looks like : {elem1,elem2, elem3,dict1,{elem4,elem5, dict2 {elem6,
elem7, dict3{..
Is it possible to parse such dictionaries into xml without any new tags
other than tags used in dictionaries.
Thanks,
Abhijeet
--
http://mail.python.org/mailman/listinfo/python-list
Re: Need to parse python dictionaries into xml
I am parsing some hardware format which finally I need to convert in xml.
The intermediate step is dicts.
So, the structure looks like this:
{chip_name:'myChip',chip_clock:'3.07',chip_peripherals:{peripheral1:{mode:'mode1',register:{}},peripheral2:{},peripheral3:{...}}}
I think this example gives good insight into kind of dict structure I am
having. Now I want to have every dict tag as xml tag with hierarchy
maintained.
Thanks
Abhijeet
On Tue, Jun 15, 2010 at 11:09 PM, Stefan Behnel wrote:
> abhijeet thatte, 16.06.2010 03:05:
>
> I am a novice Python user. I am using Python to parse some hardware
>> specifications and create xml files from them.
>> I generate dict of really huge sizes. (I am parsing some 10,000 register
>> definitions.)
>>
>
> Why do you need these intermediate dicts?
>
>
>
> So, it looks like : {elem1,elem2, elem3,dict1,{elem4,elem5, dict2 {elem6,
>> elem7, dict3{..
>>
>
> What is this hierarchy of dicts mapping to what?
>
> It's always best to provide a short extract of a real example rather than
> something you made up.
>
> Stefan
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Need to parse python dictionaries into xml
On Wed, Jun 16, 2010 at 10:57 AM, Stefan Behnel wrote:
> Hi, please avoid top-posting.
>
> abhijeet thatte, 16.06.2010 18:46:
>
> On Tue, Jun 15, 2010 at 11:09 PM, Stefan Behnel wrote:
>>
>>> abhijeet thatte, 16.06.2010 03:05:
>>>
>>>> I am a novice Python user. I am using Python to parse some hardware
>>>> specifications and create xml files from them.
>>>> I generate dict of really huge sizes. (I am parsing some 10,000 register
>>>> definitions.)
>>>>
>>>
>>> Why do you need these intermediate dicts?
>>>
>>> So, it looks like : {elem1,elem2, elem3,dict1,{elem4,elem5, dict2
>>>> {elem6,
>>>> elem7, dict3{..
>>>>
>>>>
>>> What is this hierarchy of dicts mapping to what?
>>>
>>> It's always best to provide a short extract of a real example rather than
>>> something you made up.
>>>
>> >
>
>> I am parsing some hardware format which finally I need to convert in xml.
>>
>> The intermediate step is dicts.
>> So, the structure looks like this:
>>
>> {chip_name:'myChip',chip_clock:'3.07',chip_peripherals:{peripheral1:{mode:'mode1',register:{}},peripheral2:{},peripheral3:{...}}}
>>
>
> With "real example" I meant real code and real (or close to real) data. The
> above is not a valid Python dictionary. I assume the keys are supposed to be
> strings?
>
>
>
> I think this example gives good insight into kind of dict structure I am
>> having. Now I want to have every dict tag as xml tag with hierarchy
>> maintained.
>>
>
> What is name of the root element that you want?
>
> You should start by writing down the XML structure that you want to build
> for the above dict. That will make it clear what needs to be done.
Stefan
>
> /*/
>
I need an xml file structure as below:
<#>
sh2a
32
4
<#>
PIF
4
new_string
<#>
Interrupt_tree
<#>
MX
32
1
INTR
<#>
RRPR
928
0
INTR
//**/
This is a very small part of the actual output I need.
Dicts which I am creating looks like =
{'chipsim':{'name':sh2a,'size':32,'bus_width':'4','PIF':{'name':'PIF','offseet':'4','name_of_peer_string':'new_string'},'interrupt_tree':{'tree_level_0':{'tree_level_1':{.}
> I guess ElementTree is the best way to go about it. But have not found a
> good reference on how to use it.
>
> Thanks
Abhijeet
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Need to parse python dictionaries into xml
On Wed, Jun 16, 2010 at 10:43 AM, Ian Kelly wrote:
> On Wed, Jun 16, 2010 at 10:46 AM, abhijeet thatte
> wrote:
> > I am parsing some hardware format which finally I need to convert in xml.
> > The intermediate step is dicts.
> > So, the structure looks like this:
> >
> {chip_name:'myChip',chip_clock:'3.07',chip_peripherals:{peripheral1:{mode:'mode1',register:{}},peripheral2:{},peripheral3:{...}}}
> > I think this example gives good insight into kind of dict structure I am
> > having. Now I want to have every dict tag as xml tag with hierarchy
> > maintained.
>
> You could traverse the dict, using xml.etree.ElementTree.TreeBuilder
> to build up an element tree, then use ElementTree.write() to generate
> the xml file. It's not clear why you need the dict, though. Why not
> just use the element tree as your intermediate representation?
>
> Cheers,
> Ian
> --
> http://mail.python.org/mailman/listinfo/python-list
>
> >>> Thanks Ian.
>
Can you suggest a link showing usage of TreeBuilder in such cases. I have
not come across ElementTree till this point. (Started using python 3-4 days
back). So, I thought Dicts were based to store hierarchical format. I am now
checking how to use ElementTree. Any input is welcome.
--
http://mail.python.org/mailman/listinfo/python-list
Sorting dicts inside dicts
Hi,
I have a huge dict structure like below:
*
{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}
*
Module dict and reg_dicts contain many elements than shown.
I want to sort this 'module' dictionary as per 'reg_addr' element in every
'reg_dict'.
There is no relation between 'reg_dict' suffix and address. So, reg_dict_0
can contain reg_address = 2000/72 (any number)
I do not want output in a list format as the actual dict size is huge which
I want to use based on key value pair.
So, I want output as :
*
{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}
*
*
*
Is it possible to sort the things? What I guess is Python stores dicts in a
tree like structure but I am forcing it to store the way I want. Is it
possible to do something like that.
Thanks,
--
http://mail.python.org/mailman/listinfo/python-list
Pretty printing with ElementTree
Hi, Does any one know how to use pretty printing with ElementTree while generating xml files. We can use that with lxml. But I want to stick with it ElementTree. Thanks, Abhijeet -- http://mail.python.org/mailman/listinfo/python-list
Re: Pretty printing with ElementTree
It worked. Thanks, Abhijeet On Fri, Jul 9, 2010 at 4:03 PM, John Krukoff wrote: > On Fri, 2010-07-09 at 15:46 -0700, abhijeet thatte wrote: > > Hi, > > > > > > Does any one know how to use pretty printing with ElementTree while > > generating xml files. > > We can use that with lxml. But I want to stick with it ElementTree. > > > > > > Thanks, > > Abhijeet > > > It's pretty simple minded, but this recipe from the element tree > documentation may do what you want: > http://effbot.org/zone/element-lib.htm#prettyprint > > -- > John Krukoff > Land Title Guarantee Company > > -- http://mail.python.org/mailman/listinfo/python-list
Need to import stuff
Hi, I need to import few files depending on the user input. For eg if user gives an input as "abcd" then I will have * import "abcd.py".* Can not have any hard coding in the code. Does any one know how to solve the problem. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Need to import stuff
Hi,
Thanks for the reply. But I guess it does not support nested file paths.
If user gives 'abcd' then I need to import "*/Do/Stuff/abcd*". Out of which
only *"abcd" is taken run time. Do and Stuff are fixed. *
*I got an error "*ImportError: Import by filename is not supported.". Any
solution??
On Tue, Aug 17, 2010 at 3:27 PM, Jerry Hill wrote:
> On Tue, Aug 17, 2010 at 6:21 PM, abhijeet thatte
> wrote:
> > Hi,
> > I need to import few files depending on the user input. For eg if user
> gives
> > an input as "abcd" then I will have import "abcd.py".
> > Can not have any hard coding in the code. Does any one know how to solve
> the
> > problem.
>
> Use the __import__ function (
> http://docs.python.org/library/functions.html#__import__ ), like this:
>
> user_module = __import__("abdc")
> user_module.do_stuff()
>
> --
> Jerry
>
--
http://mail.python.org/mailman/listinfo/python-list
