Search Results

Search found 14486 results on 580 pages for 'python idle'.

Page 119/580 | < Previous Page | 115 116 117 118 119 120 121 122 123 124 125 126  | Next Page >

  • Parsing a string representing a float *with an exponent* in Python

    - by Lucas
    Hi, I have a large file with numbers in the form of 6,52353753563E-7. So there's an exponent in that string. float() dies on this. While I could write custom code to pre-process the string into something float() can eat, I'm looking for the pythonic way of converting these into a float (something like a format string passed somewhere). I must say I'm surprised float() can't handle strings with such an exponent, this is pretty common stuff. I'm using python 2.6, but 3.1 is an option if need be.

    Read the article

  • % confuses python raw sql query

    - by Jonathan
    Following this SO question, I'm trying to "truncate" all tables related to a certain django application using the following raw sql commands in python: cursor.execute("set foreign_key_checks = 0") cursor.execute("select concat('truncate table ',table_schema,'.',table_name,';') as sql_stmt from information_schema.tables where table_schema = 'my_db' and table_type = 'base table' AND table_name LIKE 'some_prefix%'") for sql in [sql[0] for sql in cursor.fetchall()]: cursor.execute(sql) cursor.execute("set foreign_key_checks = 1") Alas I receive the following error: C:\dev\my_project>my_script.py Traceback (most recent call last): File "C:\dev\my_project\my_script.py", line 295, in <module> cursor.execute(r"select concat('truncate table ',table_schema,'.',table_name,';') as sql_stmt from information_schema.tables where table_schema = 'my_db' and table_type = 'base table' AND table_name LIKE 'some_prefix%'") File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 18, in execute sql = self.db.ops.last_executed_query(self.cursor, sql, params) File "C:\Python26\lib\site-packages\django\db\backends\__init__.py", line 216, in last_executed_query return smart_unicode(sql) % u_params TypeError: not enough arguments for format string Is the % in the LIKE making trouble? How can I workaround it?

    Read the article

  • Python design mistakes

    - by Andrea
    A while ago, when I was learning Javascript, I studied Javascript: the good parts, and I particularly enjoyed the chapters on the bad and the ugly parts. Of course, I did not agree with everything, as summing up the design defects of a programming language is to a certain extent subjective - although, for instance, I guess everyone would agree that the keyword with was a mistake in Javascript. Nevertheless, I find it useful to read such reviews: even if one does not agree, there is a lot to learn. Is there a blog entry or some book describing design mistakes for Python? For instance I guess some people would count the lack of tail call optimization a mistake; there may be other issues (or non-issues) which are worth learning about.

    Read the article

  • Convert Python 3.x snippet to C#/LINQ.

    - by Hamish Grubijan
    I want to sort elements of a HashSet<string> and join them by a ; character. Python interpreter version: >>> st = {'jhg', 'uywer', 'nbcm', 'utr'} >>> strng = ';'.join(sorted(s)) >>> strng 'ASD;anmbh;ashgg;jhghjg' C# signature of a method I seek: private string getVersionsSorted(HashSet<string> versions); I can do this without using Linq, but I really want to learn it better. Many thanks!

    Read the article

  • Python - Create a list with initial capacity

    - by Claudiu
    Code like this often happens: l = [] while foo: #baz l.append(bar) #qux This is really slow if you're about to append thousands of elements to your list, as the list will have to constantly be re-initialized to grow. (I understand that lists aren't just wrappers around some array-type-thing, but something more complicated. I think this still applies, though; let me know if not). In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient. I understand that code like this can often be re-factored into a list comprehension. If the for/while loop is very complicated, though, this is unfeasible. Is there any equivalent for us python programmers?

    Read the article

  • python: find and replace numbers < 1 in text file

    - by hjp
    I'm pretty new to Python programming and would appreciate some help to a problem I have... Basically I have multiple text files which contain velocity values as such: 0.259515E+03 0.235095E+03 0.208262E+03 0.230223E+03 0.267333E+03 0.217889E+03 0.156233E+03 0.144876E+03 0.136187E+03 0.137865E+00 etc for many lines... What I need to do is convert all the values in the text file that are less than 1 (e.g. 0.137865E+00 above) to an arbitrary value of 0.100000E+01. While it seems pretty simple to replace specific values with the 'replace()' method and a while loop, how do you do this if you want to replace a range? thanks

    Read the article

  • File/module structure in Python

    - by keithjgrant
    So I'm just getting started with Python, and currently working my way through diveintopython.org. The code examples are nice, but the vast majority of them are little four-line snippets, and I want to see a little more of the big picture. As I understand it--and correct me if I'm wrong--each '.py' file becomes a "module", and a group of modules in a directory becomes a "package" (at least, it does if I create a __init__.py file in that directory). What is it if I don't have a __init__.py file? So what does each "module" file look like? Do I generally define only one class in the file? Does anything else go in that file besides the class definition and maybe a handful of import commands?

    Read the article

  • Finding the most similar numbers across multiple lists in Python

    - by new_sysadmin
    In Python, I have 3 lists of floating-point numbers (angles), in the range 0-360, and the lists are not the same length. I need to find the triplet (with 1 number from each list) in which the numbers are the closest. (It's highly unlikely that any of the numbers will be identical, since this is real-world data.) I was thinking of using a simple lowest-standard-deviation method to measure agreement, but I'm not sure of a good way to implement this. I could loop through each list, comparing the standard deviation of every possible combination using nested for loops, and have a temporary variable save the indices of the triplet that agrees the best, but I was wondering if anyone had a better or more elegant way to do something like this. Thanks!

    Read the article

  • Run and terminate a prgram (Python under Windows)

    - by Fredrich
    I'd like to create a small script to that basically does this: run program1.exe -- kill program1.exe after n seconds -- run program1.exe again. I know some basic Python and would read up on this, but I'm in a bit of a hurry and just need this to get done asap. If someone has a script/idea or could help my out with just the syntax I need to open and kill the .exe file, please... I don't mind solutions in other languages either. I'm sorry if this is a bit "please write my code"-ish, that's not something I typically do.

    Read the article

  • Scrapping *.aspx content using Python

    - by tomato
    I'm having difficulties scrapping dynamically generated table in ASPX. Trying to scrap the gas prices from a site like these GasPrices. I can extract all the information in the gas price table (address, time submitted etc.), except for the actual gas price. Is there a way I could scrap the gas prices? i.e. somehow get a text representation of it. I'm not very familiar with ASP/ASPX - but what's being generated now is not showing up in the final HTML. I'm using Python to do the scrapping, but that's irrelevant unless there's a specific library...

    Read the article

  • Limit calls to external database with Python CGI

    - by Matt Ball
    I've got a Python CGI script that pulls data from a GPS service; I'd like this information to be updated on the webpage about once every 10s (the max allowed by the GPS service's TOS). But there could be, say, 100 users viewing the webpage at once, all calling the script. I think the users' scripts need to grab data from a buffer page that itself only upates once every ten seconds. How can I make this buffer page auto-update if there's no one directly viewing the content (and not accessing the CGI)? Are there better ways to accomplish this?

    Read the article

  • StringListProperty limited to 500 char strings (Google App Engine / Python)

    - by MarcoB
    It seems that StringListProperty can only contain strings up to 500 chars each, just like StringProperty... Is there a way to store longer strings than that? I don't need them to be indexed or anything. What I would need would be something like a "TextListProperty", where each string in the list can be any length and not limited to 500 chars. Can I create a property like that? Or can you experts suggest a different approach? Perhaps I should use a plain list and pickle/unpickle it in a Blob field, or something like that? I'm a bit new to Python and GAE and I would greatly appreciate some pointers instead of spending days on trial and error...thanks!

    Read the article

  • delete all records except the id I have in a python list

    - by jay_t
    Hi all, I want to delete all records in a mysql db except the record id's I have in a list. The length of that list can vary and could easily contain 2000+ id's, ... Currently I convert my list to a string so it fits in something like this: cursor.execute("""delete from table where id not in (%s)""",(list)) Which doesn't feel right and I have no idea how long list is allowed to be, .... What's the most efficient way of doing this from python? Altering the structure of table with an extra field to mark/unmark records for deletion would be great but not an option. Having a dedicated table storing the id's would indeed be helpful then this can just be done through a sql query... but I would really like to avoid these options if possible. Thanks,

    Read the article

  • Python: Check if all dictionaries in list are empty

    - by Brant
    I have a list of dictionaries. I need to check if all the dictionaries in that list are empty. I am looking for a simple statement that will do it in one line. Is there a single line way to do the following (not including the print)? l = [{},{},{}] # this list is generated elsewhere... all_empty = True for i in l: if i: all_empty = False print all_empty Somewhat new to python... I don't know if there is a shorthand built-in way to check this. Thanks in advance.

    Read the article

  • Python sqlite3 and concurrency

    - by RexE
    I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line: conn = sqlite3.connect("mydatabase.db") If I put this line of code inside each thread, I get an OperationalError telling me that the database file is locked. I guess this means that another thread has mydatabase.db open through a sqlite3 connection and has locked it. If I put this line of code in the main program and pass the connection object (conn) to each thread, I get a ProgrammingError, saying that SQLite objects created in a thread can only be used in that same thread. Previously I was storing all my results in CSV files, and did not have any of these file-locking issues. Hopefully this will be possible with sqlite. Any ideas?

    Read the article

  • Filtering Data in a Text File with Python

    - by YAS
    I'm new to Python (like Zygote new), and it's just to supplement another program but what I need is I have a text file that's a group of items for a game and it is formatted so: [1] Name=Blah Faction=Blahdiddly Cost=1000 [2] Name=Meh Faction=MehMeh Cost=2000 [3] Name=Lollypop Faction=Blahdiddly Cost=100 And I need to be able to find out what groups (the numbers in brackets) have matching values. So if I search Faction=Blahdiddly Group 1 & 3 will come up. I unfortunately have NO idea how to do this. Can anyone help?

    Read the article

  • python -> combinations of numbers and letters

    - by tekknolagi
    #!/usr/bin/python import random lower_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] all = [] all = " ".join("".join(lower_a) + "".join(upper_a) + "".join(num)) all = all.split() x = 1 c = 1 while x < 10: y = [] for i in range(c): a = random.choice(all) y.append(a) print "".join(y) x += 1 c += 1 what i have now outputs something like the following: 5 hE HAy 1kgy Pt6JM 2pFuCb Jv5osaX 5q8PwWAO SvHWRKfI5 how can i make it systematically go through every combination of letters (upper and lowercase) for a given length, then add 1 to that length and repeat the process?

    Read the article

  • Update existing columns and rows within csv file using Python

    - by wilbev
    So I've been attempting to use the csv module in Python to add data to existing rows and columns, but only specific columns of each row. So for examples let's say my existing csv file has the following: id, name, city, age 1, Ed,, 34 2, Pat,, 23 So basically the city of each person is missing, so I would like to update each row with that person's city. However, the writerow method only seems replace the existing data within the csv file. Changing the open file to append mode just adds the data to a new row. Is there any way to skip the existing data, and only add the city to each row? Thanks

    Read the article

  • making errorbars not clipped in matplotlib with Python

    - by user248237
    I am using matplotlib in Python to plot a line with errorbars as follows: plt.errorbar(xvalues, up_densities, yerr=ctl_sds, fmt='-^', lw=1.2, markersize=markersize, markeredgecolor=up_color, color=up_color, label="My label", clip_on=False) plt.xticks(xvalues) I set the ticks on the x-axis using "xticks". However, the error bars of the last point in xvalues (i.e. xvalues[-1]) are clipped on the right -- meaning only half an error bar appears. This is true even with the clip_on=False option. How can I fix this, so that the error bars appear in full, even though their right side is technically outside xvalues[-1]? thanks.

    Read the article

  • Maintaining Logging and/or stdout/stderr in Python Daemon

    - by dave mankoff
    Every recipe that I've found for creating a daemon process in Python involves forking twice (for Unix) and then closing all open file descriptors. (See http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ for an example). This is all simple enough but I seem to have an issue. On the production machine that I am setting up, my daemon is aborting - silently since all open file descriptors were closed. I am having a tricky time debugging the issue currently and am wondering what the proper way to catch and log these errors are. What is the right way to setup logging such that it continues to work after daemonizing? Do I just call logging.basicConfig() a second time after daemonizing? What's the right way to capture stdout and stderr? I am fuzzy on the details of why all the files are closed. Ideally, my main code could just call daemon_start(pid_file) and logging would continue to work.

    Read the article

  • Adding anchors to h2 in text using python and regexp

    - by Oli
    I'm trying to add anchors to all h2's in my html, using python. This code will add those anchors, but I need to fill the name of the anchors too. Any idea if the name can be the number of the match in the loop or a slugified version of the text between the h2 tags? Here's the code so far: regex = '(?P<name><h2>.*?</h2>)' text = re.sub(regex, "<a name=''/>"+r"\g<name>", text)

    Read the article

  • unittest in python: ignore an import from the code I want to test

    - by vaidab
    I have a python program that imports pythoncom (and uses pythoncom.CoCreateInstance from it). I want to create a unittest for the program logic without it importing pythoncom (so I can run the test on Linux as well). What options are there? Can I do it without modifying the system under test? What I found so far: sys.modules["pythoncom"] = "test" import module_that_imports_pythoncom My problem with it is if I have: from pythoncom.something import something I'll get: ImportError: No module named something.something And sys.modules["something.something"] or sys.modules["pythoncom.something.something"] doesn't work. Any ideas?

    Read the article

  • limiting the rate of emails using python

    - by Ali
    I have a python script which reads email addresses from a database for a particular date, example today, and sends out an email message to them one by one. It reads data from MySQL using the MySQLdb module and stores all results in a dictionary and sends out emails using : rows = cursor.fetchall () #All email addresses returned that are supposed to go out on todays date. for row is rows: #send email However, my hosting service only lets me send out 500 emails per hour. How can I limit my script from making sure only 500 emails are sent in an hour and then to check the database if more emails are left for today or not and then to send them in the next hour. The script is activated using a cron job.

    Read the article

  • Looking for python lib to manage remote tasks

    - by Riz
    Hi, I have server with django on it, this server runs some manage.py commands and update database. Now I need to move some of this tasks to different servers. I don't want to allow remote db access and need some tool\lib to be able to start task on remote servers by main server's command and update tasks code/add new tasks. I have ssh access to every server, all servers run under debian and all code in python. I was thiking about creating my own xmpp based solution(server sends messages to slave servers with commands to execute, like "update task", "run task"), or maybe some low-level ssh based solution where main server logs to slave servers and executes bash commands. But I would be happy to hear any advices.

    Read the article

< Previous Page | 115 116 117 118 119 120 121 122 123 124 125 126  | Next Page >