Can't get a simple TCP program to work
The following *extremely* simple script complains that "Socket is not connected" when I try to call recv. Could anyone provide some quick guidance? http://pastebin.com/m64317b32 -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Python like lanugages [was Re: After C++, what with Python?]
Cobra seems to similar to python. Or it at least compares itself to python. -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Python like lanugages [was Re: After C++, what with Python?]
Anyone have thoughts on Cobra? On Jan 18, 2011 4:20 PM, "Zach" wrote: > Cobra seems to similar to python. Or it at least compares itself to python. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the Most Efficient Way of Printing A Dict's Contents Out In Columns?
> d={'Header2': ['2', '5', '8'], 'Header3': ['3', '6', '9'], > 'Header1': ['1', '4', '7'], 'Header4': ['10', '11', '12']} > > arr = [] > for key,value in d.items(): > line = ['{:>10s}'.format(key)] > for num in value: > line.append('{:>10s}'.format(num)) > arr.append(line) > > for line in zip(*arr): > for item in line: > print(item, end='') > print() # newline > >>> > Header2 Header3 Header1 Header4 > 2 3 1 10 > 5 6 4 11 > 8 9 7 12 > > For zip(*arr) to work properly, each line of arr should have the same > length, which means that either each value of d has the same length or > that you find the max length and pad lines with blanks up to the max > length. The code above assumes the first. > > If the items in each value of d are not strings, more fiddling is > needed. The printed field size is also arbitrary. It needs adjusting for > the actual max length. You might want to adjust it for each key-value > pair in the dict, which is to say, each column of the resulting table. > > -- > Terry Jan Reedy I just have one quick question. On the line where you have zip(*arr), what is the * for? Is it like the pointer operator, such as with C? Or is it exactly the pointer operator? Otherwise, thank you for the example! This isn't homework, but I'm working on something at work, and I was wondering how to properly format the output from CSV files into another file. It's all a part of an analyzer script for database tables, and the table wherein. Thank you a bunch for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Function within class and in modules
> On Jun 15, 7:57 am, TheSaint wrote: > Hello > sorry, I'm bit curious to understand what could be the difference to pack up > a class for some number of functions in it and a simple module which I just > import and use the similar functions? > The only perspective that I think of is that class might instantiate a > function several time. For my use I don't have multithread and mostly > programs are sequencial. I had a hard time with this at first when I started using Python. I personally come from a background of using Java in an educational environment, so I'm pretty familiar with it. Going from a "pure" Object-Oriented language, where everything MUST be bundled into a class, and an Object is less of "a bit of data" and more of "a data structure that actually DOES something", was a little difficult. Just repeat this to yourself: Python ISN'T Java. Repeat it until the words start sounding funny to you. Then continue for another 10 minutes. It'll sink in. Anyhow... In Python, classes aren't necessarily treated as "things that do stuff" (though they can DEFINITELY act in that way!). Python classes are made to hold data. If you have something that you need to save for later, put it in a class and call it a day. If you only have a bunch of functions that are meant to process something, just put them into a module. You'll save yourself some time, you won't have to instantiate a class in order to call the functions, and you'll be happier overall. (I know was happy from being freed from the Pure OO model that Java shoves down your throat!) -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for Coders or Testers for an Open Source File Organizer
On Jun 14, 8:22 pm, zainul franciscus wrote: > Thank you for the reply. I should have mentioned where I am hosting > the code *doh slap on the wrist. > > I am hosting the code in google > code:http://code.google.com/p/mirandafileorganizer/ > > There is a link to the user/developer guide on how to get started with > the > software:https://docs.google.com/document/d/1OGvrS5offb27WlkZ5genMJX2El18Aqrnf... > > Just email me directly if you are interested to join the project and I > will add you as a contributor in Google Code > > Best Wishes Sounds good, I shall take a look at it when I get home from work. (The Google Docs domain is blocked here. Curses!) Just as a tip: on the project's homepage, just write about your project and what it's features are. Don't write in the first person. This isn't about you, it's about the project. O=) -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for Coders or Testers for an Open Source File Organizer
Also, can I be added to the project? Email is zcdzi...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE/Eclipse
I've honestly always used either PyDev or IDLE. However, Python is pretty easy to usd without a big IDE slowing you down, so you could also use a developer's text editor like Notepad++ or gedit and still be good. -- http://mail.python.org/mailman/listinfo/python-list
Python Requests logging 401 immediately before 200
Hi everyone, I'm using MarkLogic and have a Python script set up to check for documents using Requests (http://docs.python-requests.org/en/latest/) and I have logging included in the script. I have logging set to the DEBUG level. When I set the script to simple search and return the HTTP status code for items it works, but when I look at what is generated by logging I see the following for everything: INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost DEBUG:requests.packages.urllib3.connectionpool:"GET /v1/documents?uri=000248e4331d4db5856df8fd427b3cdb.xml HTTP/1.1" 401 211 DEBUG:requests.packages.urllib3.connectionpool:"GET /v1/documents?uri=000248e4331d4db5856df8fd427b3cdb.xml HTTP/1.1" 200 18327 As you can see the 400 and the 200 are the same document (only 1 can exist in ML with the same URI) and in MarkLogic's logs both are executed at the same time. When I search for a document using something like CURL for instance, I only get the 200 status code which seems correct to me. Is this something I should be concerned about and should fix or is it just the log level I have set or something else I shouldn't worry about? Thank you for your help! Here's a snipped of my code in case it helps: import requests import logging # initiate logging log_path = os.path.join('my_log.log') logging.basicConfig(filename=log_path,level=logging.DEBUG) # make request r = requests.get('http://localhost:8004/v1/documents?uri=000248e4331d4db5856df8fd427b3cdb.xml',auth=HTTPDigestAuth('USER', 'PASSWORD')) print r.status_code -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Requests logging 401 immediately before 200
On Friday, February 20, 2015 at 12:31:00 PM UTC-5, Chris Angelico wrote: > On Sat, Feb 21, 2015 at 4:16 AM, Zach Dunlap wrote: > > INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection > > (1): localhost > > DEBUG:requests.packages.urllib3.connectionpool:"GET > > /v1/documents?uri=000248e4331d4db5856df8fd427b3cdb.xml HTTP/1.1" 401 211 > > DEBUG:requests.packages.urllib3.connectionpool:"GET > > /v1/documents?uri=000248e4331d4db5856df8fd427b3cdb.xml HTTP/1.1" 200 18327 > > > > As you can see the 400 and the 200 are the same document (only 1 can exist > > in ML with the same URI) and in MarkLogic's logs both are executed at the > > same time. > > > > Is this something I should be concerned about and should fix or is it just > > the log level I have set or something else I shouldn't worry about? > > > > r = > > requests.get('http://localhost:8004/v1/documents?uri=000248e4331d4db5856df8fd427b3cdb.xml',auth=HTTPDigestAuth('USER', > > 'PASSWORD')) > > > > Short explanation: It's part of the protocol. > > You're using Digest Auth, so what's happening here is that a request > is sent without the authentication, and the inevitable 401 response is > the signal that the request should be re-sent with credentials. > > There's a massive debate as to whether or not it's correct to send > unsolicited credentials. On the one hand, this "401 then 200" pattern > takes extra internet round-trips (not that that's a big deal with > localhost, but it's the same issue everywhere) and puts extra load on > both server and client; but on the other hand, nobody wants their > credentials sent to the wrong server, and it's not always easy to tell > when they'll be needed. Without the 401, you can't know whether or not > you need to authenticate, so if once you start sending unsolicited > credentials, you basically have to keep on doing so. > > If you don't have a problem with performance or latency, then consider > this to be nothing more than a bit of log file spam. I'm not sure if > the Python requests module can be easily configured to send > credentials on the first query, but my advice is: don't even bother > looking into that unless you have need to. > > All the best! > > ChrisA Thanks very much for this it's extremely helpful! This clears it up and I think I will ignore it as log spam as you suggest. -- https://mail.python.org/mailman/listinfo/python-list
Problems with code
Hi, I am trying to call an unbound method (Map.Background) but getting the following error: TypeError: unbound method background() must be called with Map instance as first argument (got nothing instead) Here is some of the code(not completed) Thanks in Advance - Zach Code: class Knight(games.Sprite): """ A moving knight. """ SWORD_DELAY = 50 sword_wait = 0 def update(self): """ moving knight based on keys pressed. """ if games.keyboard.is_pressed(games.K_w): self.y -= 3 self.angle = 0 if games.keyboard.is_pressed(games.K_s): self.y += 3 self.angle = 180 if games.keyboard.is_pressed(games.K_a): self.x -= 3 self.angle = 270 if games.keyboard.is_pressed(games.K_d): self.x += 3 self.angle = 90 if self.top > games.screen.height: self.bottom = 0 if self.bottom < 0: self.top = games.screen.height Map.background() if self.left > games.screen.width: self.right = 0 if self.right < 0: self.left = games.screen.width class Map(games.Sprite): def background(self): new_back = games.load_image("map3.jpg", transparent = False) games.screen.background = new_back -- http://mail.python.org/mailman/listinfo/python-list
methods and class methods
I just learned python programming and is wondering how to change a method to a class method. Also what are the differences between a method and class method. Thanks in advance - Zach (Freshman student in High school) -- http://mail.python.org/mailman/listinfo/python-list
automating python programs
Hi, I'm trying to figure out how to run a python program on a schedule, maybe every half an hour... Is this possible? Thanks! -Zach -- http://mail.python.org/mailman/listinfo/python-list
Running python scripts in a VB program
Does anyone have any clue on how to embed python scripts in a visual basic windows app? Additionally, does anybody else feel like Visual Basic is ridiculously confusing? Any help is appreciated. Thanks, -Zach -- http://mail.python.org/mailman/listinfo/python-list
Shared script
I wrote a script that several different people on different machines need to run on a regular basis. When I first wrote it, it was in crisis mode, I got something out that was quick and dirty, very bare bones. Recently I had some more time, so I pushed most of the functions that the script uses into a module, because I use those functions on a pretty regular basis. My problem is this: The module is on MY machine in MY Python25 folder. I like it there, because like I said, I use the functions within it on a pretty regular basis. However, the other people who need to run the original script don't have the module. My quick fix was to throw the module into the shared folder, which works, but means everytime I have to update the module I have to update 2 different files, the one in my Python25 folder and the one in the shared network folder. Is there a better way to do this, short of asking everybody else to put the module in thir Python 25 folder (which would mean me e-mailing them to update the module, and then assuming that they did) ?!? Thanks, Zach -- http://mail.python.org/mailman/listinfo/python-list
Executing a python script while it is running
Hi everybody, Here's my situation: I have a batch file that calls a python script. This batch file is triggered by an outside application when the application completes a task. The problem is that while the batch file (and pythons script) is running, the application will complete the next task, and try to call the batch file again (while it is already running) Hopefully that's not too confusing. I'm not sure what direction to go with this, any help or nudges in the RIGHT direction would be greatly appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a python script while it is running
> A lot more information would be useful. What version of Python, and what > operating system environment? Exactly what would you like to happen when > the batch file is invoked a second time? I'm running Python 2.6.2 on Windows. I'm passing filenames to the batch files and I need all filenames to be processed. I can't have any fails. I'm working on logging any fails I do have so that I can maybe batch process at the end of the day. > 2) let them both run as separate processes This sounds like a good option, but I'm not totally sure on how to go about this? > 4) queue something to be processed when the first run finishes I had the same idea, but I believe it would involve having another python script run all day long, which wouldn't necessarily be a bad thing, but I'd like to explore other options as well. > What provisions does this existing application have for long-running batch > files? Seems the synchronization ought to happen there. Do you have any > constraints on how long your script might take, worst case? What if the > application finishes its tasks at a faster average rate than your script can > process them? The batch file is moving large video files. Duration probably ranges from 10 sec to 45 mins. On average, the application takes longer to process the files than it does the batch file/python script takes to copy them, but I'm concerned about the occasional time that the application finishes a small file right after finishing a large file. Thanks for your response! -Zach -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Executing a python script while it is running
On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebert wrote: > On Tue, Jun 16, 2009 at 6:21 PM, wrote: >> Hey Dave, >> >> Thanks for the helpful responses. >> >>> Option 2 is what you get by default. Naturally it depends on what the >>> application is using to launch the batch file, but the most common cases >>> will launch a separate process. >> >> The app ended up delaying starting the second batch file until it finished >> the first. I had the app trigger an infinite loop on completion, and sent >> two files through at the same time. The second file finished seconds after >> the first, but the batch file didn't trigger until I closed the first one. > > Are you sure you aren't unknowingly having the app wait on the first > batch file process until it terminates? How exactly are you launching > the batch files? > > Cheers, > Chris > -- > http://blog.rebertia.com Hey Chris, I actually think that's what's happening, which is fine in my case (for now anyway) as I just need them all to complete, we don't need them running at the same time. I'm using a job management system, and they have the option of triggering a command line after completing a job. A better/safer solution might be spawning another job and re-inserting to the jms queue. Thanks again, Zach -- http://mail.python.org/mailman/listinfo/python-list
Config files with different types
Hi all, I've written a function that reads a specifically formatted text file and spits out a dictionary. Here's an example: config.txt: Destination = C:/Destination Overwrite = True Here's my function that takes 1 argument (text file) the_file = open(textfile,'r') linelist = the_file.read().split('\n') the_file.close() configs = {} for line in linelist: try: key,value = line.split('=') key.strip() value.strip() key.lower() value.lower() configs[key] = value except ValueError: break so I call this on my config file, and then I can refer back to any config in my script like this: shutil.move(your_file,configs['destination']) which I like because it's very clear and readable. So this works great for simple text config files. Here's how I want to improve it: I want to be able to look at the value and determine what type it SHOULD be. Right now, configs['overwrite'] = 'true' (a string) when it might be more useful as a boolean. Is there a quick way to do this? I'd also like to able to read '1' as an in, '1.0' as a float, etc... I remember once I saw a script that took a string and tried int(), float() wrapped in a try except, but I was wondering if there was a more direct way. Thanks in advance, Zach -- http://mail.python.org/mailman/listinfo/python-list
Re: Config files with different types
yaml looks pretty interesting. Also, I wouldn't have to change much, I would still use the same function, and still output a dict. Thanks! -Zach On Thu, Jul 2, 2009 at 11:55 PM, Javier Collado wrote: > Hello, > > Have you considered using something that is already developed? > > You could take a look at this presentation for an overview of what's > available: > http://us.pycon.org/2009/conference/schedule/event/5/ > > Anyway, let me explain that, since I "discovered" it, my favourite > format for configuration files is yaml (http://yaml.org/, > http://pyyaml.org/). It's easy to read, easy to write, available in > different programming languagues, etc. In addition to this, type > conversion is already in place so I think it covers your requirement. > For example: > > IIn [1]: import yaml > > In [2]: yaml.load("""name: person name > ...: age: 25 > ...: is_programmer: true""") > Out[2]: {'age': 25, 'is_programmer': True, 'name': 'person name'} > > Best regards, > Javier > > 2009/7/2 Zach Hobesh : >> Hi all, >> >> I've written a function that reads a specifically formatted text file >> and spits out a dictionary. Here's an example: >> >> config.txt: >> >> Destination = C:/Destination >> Overwrite = True >> >> >> Here's my function that takes 1 argument (text file) >> >> the_file = open(textfile,'r') >> linelist = the_file.read().split('\n') >> the_file.close() >> configs = {} >> for line in linelist: >> try: >> key,value = line.split('=') >> key.strip() >> value.strip() >> key.lower() >> value.lower() >> configs[key] = value >> >> except ValueError: >> break >> >> so I call this on my config file, and then I can refer back to any >> config in my script like this: >> >> shutil.move(your_file,configs['destination']) >> >> which I like because it's very clear and readable. >> >> So this works great for simple text config files. Here's how I want >> to improve it: >> >> I want to be able to look at the value and determine what type it >> SHOULD be. Right now, configs['overwrite'] = 'true' (a string) when >> it might be more useful as a boolean. Is there a quick way to do >> this? I'd also like to able to read '1' as an in, '1.0' as a float, >> etc... >> >> I remember once I saw a script that took a string and tried int(), >> float() wrapped in a try except, but I was wondering if there was a >> more direct way. >> >> Thanks in advance, >> >> Zach >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- http://mail.python.org/mailman/listinfo/python-list
Mimicing an HTML form
Hi all, I'm having alot of trouble automating the submitting of form. I have an HTML page that works and it looks like this: When I put valid values for the handling script an app ID, this page works. Now I'm trying to turn this same functionality into a script. Here's my code: import urllib import os import urllib2 appID = *value here* video = os.path.normpath(os.getcwd() + '/news.wmv') title = 'News' desc = 'Here is a sample News video' uploader = *script here* print "Encoding url..." data = urllib.urlencode({"FileUploadedVideo": video, "hdnADCID" : appID, "txtTitle" : title, "txtDescription": desc}) user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = { 'User-Agent' : user_agent } print "Calling url..." req = urllib2.Request(uploader, data, headers) response = urllib2.urlopen(req) s = response.read() response.close() print "Writing results..." result = open('result.html','w') result.write(s) result.close() Does anybody have any suggestions? I keep on getting bad request, so I'm assuming that the html page is passing something that my script is not. Is there some way to scrape the POST request from the html form? Thanks, Zach -- http://mail.python.org/mailman/listinfo/python-list
Dataframe iterating question : 3 ways of calling a row and column
I wouldn't say I'm a Python noob, but I wouldn't say I'm a Python expert either. I work in data science and use Pandas Dataframes a lot. My question is regarding the difference in calling out a specific row, column combination in a dataframe. I see 3 ways of doing this: (1) df.loc[row_ind, column_ind] (2) df.column_ind.loc[row_ind] (3) df[column_ind].loc[row_ind] where column_ind is the column name & row_ind is the named row index/row name in the dataframe. Can anyone enlighten me as to the differences between the above 3 methods of getting to the same cell in the dataframe? Are there speed differences? Is it simply a preference thing? Is there a PEP8 preferred way of doing this? Are there specific disadvantages to any of the methods? Thanks in advance. Zach -- https://mail.python.org/mailman/listinfo/python-list