Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-27 Thread Tim Chase
On 2013-11-27 20:08, Roy Smith wrote: > > How do you expect people to know they're using a local idiom? > > Look it up in Urban Dictionary and Bob's your uncle. I thought that's how one could tell if it was an *inappropriate* idiom. As a matter of fact, I'm surprised that "Bob's your uncle" does

Re: Python and PEP8 - Recommendations on breaking up long lines?

2013-11-28 Thread Tim Chase
On 2013-11-28 03:58, Steven D'Aprano wrote: >> input = open(self.full_path) >> output = open(self.output_csv, 'ab') >> with input as input, output as output: >> ... > > That's really clever! Why didn't I think of that? Because if the 2nd output fails, the input doesn't get

Re: Need help with programming in python for class (beginner level)

2013-11-29 Thread Tim Chase
On 2013-11-29 16:31, farhan...@gmail.com wrote: > It's for a school assignment. Thanks for the honesty--you'll get far more helpful & useful replies because of that. :-) > put them into a variable I called "number" but it seems to glitch > out that variable is in any command other than "print num

Re: Need help with programming in python for class (beginner level)

2013-11-29 Thread Tim Chase
On 2013-11-30 00:59, Mark Lawrence wrote: > Wrong again, or at least overengineered. > > print "The total rolled was:", number, " ^ > > You don't even need the spaces as print kindly does it for you :) but you could at least include the missing quotati

Re: Python Unicode handling wins again -- mostly

2013-11-30 Thread Tim Chase
On 2013-12-01 00:22, Steven D'Aprano wrote: > * KELVIN SIGN versus LATIN CAPITAL LETTER A I should hope so ;-) -tkc -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Unicode handling wins again -- mostly

2013-11-30 Thread Tim Chase
On 2013-12-01 00:54, Steven D'Aprano wrote: > On Sat, 30 Nov 2013 18:52:48 -0600, Tim Chase wrote: > > > On 2013-12-01 00:22, Steven D'Aprano wrote: > >> * KELVIN SIGN versus LATIN CAPITAL LETTER A > > > > I should hope so ;-) > >

Re: Extending the 'function' built-in class

2013-12-01 Thread Tim Chase
On 2013-12-01 19:18, G. wrote: > Hi, I can't figure out how I can extend the 'function' built-in > class. I tried: class test(function): > def test(self): > print("test") > but I get an error. Is it possible ? While I don't have an answer, I did find this interesting. First, "function"

Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers?

2013-12-03 Thread Tim Chase
On 2013-12-03 15:47, Piotr Dobrogost wrote: > > The getattr function is meant for when your attribute name is in a > > variable. Being able to use strings that aren't valid identifiers > > is a side effect. > > Why do you say it's a side effect? I think random832 is saying that the designed pu

Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers?

2013-12-04 Thread Tim Chase
On 2013-12-04 21:33, Chris Angelico wrote: > I don't think so. What the OP asked for was: > > my_object.'valid-attribute-name-but-not-valid-identifier' > > Or describing it another way: A literal string instead of a token. > This is conceivable, at least, but I don't think it gives any > advantag

Re: Input without line break, is it possible?

2013-12-04 Thread Tim Chase
On 2013-12-04 07:38, geezl...@gmail.com wrote: > for i in range(8): >n = input() > > When we run it, consider the numbers below is the user input, > > 1 > 2 > 3 > 4 > 5 > 6 > (and so forth) > > my question, can i make it in just a single line like, > > 1 2 3 4 5 6 (and so forth) Not easily

Re: Input without line break, is it possible? [correction]

2013-12-04 Thread Tim Chase
On 2013-12-04 09:55, Tim Chase wrote: > You could make it a bit more robust with something like: > > answers = [] > while len(answers) < 8: > s = input() > answers.append(s.split()) this should be answers.extend(s.split()) instead of .append() That's w

Re: Eliminate "extra" variable

2013-12-06 Thread Tim Chase
On 2013-12-06 11:37, Igor Korot wrote: > def MyFunc(self, originalData): > data = {} > for i in xrange(0, len(originalData)): >dateStr, freq, source = originalData[i] >data[str(dateStr)] = {source: freq} this can be more cleanly/pythonically written as def my_

Re: Managing Google Groups headaches

2013-12-07 Thread Tim Chase
On 2013-12-07 11:08, Roy Smith wrote: > In article <31f1bb84-1432-446c-a7d4-79ce16f2a...@googlegroups.com>, > wxjmfa...@gmail.com wrote: > > > It is on this level the FSR fails. > > What is "FSR"? I apologize if this was explained earlier in the > thread and I can't find the reference. Flexibl

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-08 15:04, Peter Otten wrote: > > data = dict( > > (str(date), {source: freq}) > > for date, freq, source in original_data > > ) > > or even just > > data = {str(date): {source: freq} > for date, freq, source in original_data} I maintain enough pre-2.7 c

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-07 23:14, Igor Korot wrote: > def MyFunc(self, originalData): > self.dates = [] > data = {} > dateStrs = [] > for i in xrange(0, len(originalData)): > dateStr, freq, source = originalData[i] > data[str(dateStr)] = {source: freq} >

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-08 19:10, Mark Lawrence wrote: > On 08/12/2013 18:58, Tim Chase wrote: > > On 2013-12-07 23:14, Igor Korot wrote: > > [big snip] > > Whenever I need date manipulations I always reach out to this > http://labix.org/python-dateutil But based on the OP's

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-08 12:58, Igor Korot wrote: > Also, the data comes from either SQLite or mySQL and so to eliminate > the difference between those engines dates are processed as strings > and converted to dates for the calculation purposes only. > Maybe I will need to refactor SQLite processing to get th

Re: Possible PEP Submission

2013-12-09 Thread Tim Chase
On 2013-12-09 14:36, Logan Collins wrote: > Just checking whether 1) a PEP is the proper place for this and 2) > what y'all think about it. > > I would like to propose a change to the the 're' standard library to > support iterables. > > So, something like the following would work: > > import re

Unit testing asynchronous processes

2013-12-10 Thread Tim Chase
I've got some code that kicks off a background request to a remote server over an SSL connection using client-side certificates. Since the request is made from a separate thread, I'm having trouble testing that everything is working without without spinning up an out-of-band mock server and actual

Re: grab dict keys/values without iterating ?!

2013-12-10 Thread Tim Chase
On 2013-12-11 02:02, Tamer Higazi wrote: > Is there a way to get dict by search terms without iterating the > entire dictionary ?! > > Let us assume I have: > > {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'}

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 13:44, Steven D'Aprano wrote: > If necessary, I would consider having 26 dicts, one for each > initial letter: > > data = {} > for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": > data[c] = {} > > then store keys in the particular dict. That way, if I wanted keys > starting with Aa, I woul

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 09:46, Roy Smith wrote: > The problem is, that doesn't make a whole lot of sense in Python. > The cited implementation uses dicts at each level. By the time > you've done that, you might as well just throw all the data into > one big dict and use the full search string as the key. I

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Tim Chase
On 2013-12-11 11:10, brian cleere wrote: > filename = sys.argv[1] > column = int(sys.argv[2]) > > for line in filename() , column (): > elements = line.strip().split(',') > values.append(int(elements[col])) 1) you need to open the file 2) you need to make use of the csv module on that fi

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Tim Chase
On 2013-12-12 07:03, Chris Angelico wrote: > Also common, but how do you specify a keyword, then? Say you have a > command with subcommands: > > $0 foo x y > Move the foo to (x,y) > $0 bar x y z > Go to bar X, order a Y, and Z it [eg 'compress', 'gzip', 'drink'] > > How do you show that x/y/z are

Re: min max from tuples in list

2013-12-12 Thread Tim Chase
On 2013-12-12 11:44, Steven D'Aprano wrote: > In any case, sorting in Python is amazingly fast. You may be > pleasantly surprised that a version that sorts your data, while > nominally O(N log N), may be much faster than an O(N) solution that > doesn't require sorted data. If I were a betting man,

Re: Is it more CPU-efficient to read/write config file or read/write sqlite database?

2013-12-14 Thread Tim Chase
On 2013-12-14 07:29, JL wrote: > I have a number of python processes which communicate with each > other through writing/reading config text files. The python > ConfigParser is used. I am wondering if it is more CPU-efficient to > switch to using sqlite database instead of using configuration > fil

Re: Eliminate "extra" variable

2013-12-15 Thread Tim Chase
On 2013-12-14 23:49, Igor Korot wrote: > Tim, > > On Sun, Dec 8, 2013 at 2:18 PM, Tim Chase wrote: >>>>> conn = sqlite3.connect('x.sqlite', >>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) Your example code omitted this one crucia

Re: Eliminate "extra" variable

2013-12-15 Thread Tim Chase
On 2013-12-15 06:17, Tim Chase wrote: >>>>>> conn = sqlite3.connect('x.sqlite', >>>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > > Your example code omitted this one crucial line. Do you specify the > detect_types parameter to co

Re: Is it more CPU-efficient to read/write config file or read/write sqlite database?

2013-12-15 Thread Tim Chase
On 2013-12-16 10:12, Cameron Simpson wrote: > On 14Dec2013 10:15, Tim Chase wrote: > Annoyingly, sqlite: > > + only lets one process access the db at a time, taking you back > to a similar situation as with config files Is this a Python limitation? According to the docs[1], it

Re: Question RE urllib

2013-12-16 Thread Tim Chase
On 2013-12-16 04:40, Jeff James wrote: > These sites do not require a logon in order for the home > page to come up. Could this be due to some port being blocked > internally ? Only one of the sites reporting as down is "https" but > all are internal sites. Is there some other component I should

Re: [newbie] Saving binaries in a specific way

2013-12-16 Thread Tim Chase
On 2013-12-16 14:19, Djoser wrote: > I am new to this forum and also to Python, but I'm trying hard to > understand it better. Welcome aboard! > I need to create a binary file, but the first 4 lines must be in > signed-Integer16 and all the others in signed-Integer32. I have a > program that doe

Re: Struggling for inspiration with lists

2013-12-17 Thread Tim Chase
On 2013-12-18 03:51, Denis McMahon wrote: > I need to keep the timestamp / data association because I need to > generate output that identifies (a) the longest repeated sequence > (b) how many elements in the longest repeated sequence (c) at what > timestamps each occurrence started. > > I'm not

Re: Is it more CPU-efficient to read/write config file or read/write sqlite database?

2013-12-18 Thread Tim Chase
On 2013-12-18 09:49, dick wrote: > Don't forget that most hard disks have an option to cache the write > data. This is a 'feature' that allows the manufacturers to claim > better write performance. You can't be sure when the data is written > to the disk if that option is in play. However, my unde

Re: Is it more CPU-efficient to read/write config file or read/write sqlite database?

2013-12-18 Thread Tim Chase
On 2013-12-18 15:14, dick wrote: >>However, my understanding is that they have a small on-drive >>battery/capacitor that stores sufficient energy for the cached >>write(s) to complete in the event the system's power abruptly cuts >>off. >> >>Granted, this is purely hearsay, as it's been a long time

Re: Why Python is like C++

2013-12-21 Thread Tim Chase
On 2013-12-21 08:43, Tim Chase wrote: > Then there's the 6502 assembly on that Apple with its 2 user-facing > registers (plus the Instruction Pointer and Stack Pointer), so I > guess you could say that it has 1-bit variable names ;-) Doh, forgot momentarily that the 6502 had X, Y,

Re: Why Python is like C++

2013-12-21 Thread Tim Chase
On 2013-12-21 11:19, Christian Gollwitzer wrote: > GW-BASIC was a weak language, but two significant characters is > definitely too few. I think it was eight. Never used QuickBasic, I > went Turbo Pascal instead, which had 32 significant characters. In know that my first BASIC, Applesoft BASIC ha

Re: Why Python is like C++

2013-12-21 Thread Tim Chase
On 2013-12-21 10:59, Roy Smith wrote: > > In know that my first BASIC, Applesoft BASIC had the 2-character > > names, and you had to load Integer Basic (with Ints in addition > > to the standard Floats used in the BASIC provided by the ROM, a > > strange choice). > > Why is it a strange choice?

Re: cascading python executions only if return code is 0

2013-12-26 Thread Tim Chase
On 2013-12-27 12:44, Chris Angelico wrote: > On Fri, Dec 27, 2013 at 12:37 PM, Roy Smith wrote: > > In article , > > Ethan Furman wrote: > > > >> Mostly I don't want newbies thinking "Hey! I can use assertions > >> for all my confidence testing!" > > > > How about this one, that I wrote yes

Re: Ifs and assignments

2014-01-02 Thread Tim Chase
On 2014-01-02 17:20, John Allsup wrote: > m = r1.search(w) > if m: > handleMatch1(m) > else: > m = r2.search(w) > if m: > handleMatch2(m) > else: > print("No match") > > if not running unnecessary matches, yet capturing groups in the > event of a

Re: django question

2014-01-04 Thread Tim Chase
On 2014-01-04 15:30, Igor Korot wrote: > Does anybody here use django? Yes. However there's also a Django-users mailing list[1] for Django-specific questions. Folks there are friendly & helpful. > Is it possible to display a data grid table with django? The short answer is yes. > Basically I

Re: django question

2014-01-05 Thread Tim Chase
On 2014-01-05 00:24, Igor Korot wrote: > > While I prefer Django for larger projects, for a lighter-weight > > project such as what you describe, I'd be tempted to go with > > something a little more light-weight unless you need additional > > interactivity. I've recently been impressed with Bottl

Re: "More About Unicode in Python 2 and 3"

2014-01-05 Thread Tim Chase
On 2014-01-05 23:24, Roy Smith wrote: > $ hexdump data > 000 d7 a8 a3 88 96 95 > > That's EBCDIC for "Python". What would I write in Python 3 to read > that file and print it back out as utf-8 encoded Unicode? > > Or, how about a slightly different example: > > $ hexdump data > 000 43 6

Re: "More About Unicode in Python 2 and 3"

2014-01-06 Thread Tim Chase
On 2014-01-06 15:51, Chris Angelico wrote: > >>> data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to > >>> turn a hex dump into a bytes literal? Depends on how you source them: # space separated: >>> s1 = "43 6c 67 75 62 61" >>> ''.join(chr(int(pair, 16)) for pair in s1.split()) 'Clgu

Re: "More About Unicode in Python 2 and 3"

2014-01-06 Thread Tim Chase
On 2014-01-06 22:20, Serhiy Storchaka wrote: > data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to > turn a hex dump into a bytes literal? > > >>> bytes.fromhex('43 6c 67 75 62 61') > b'Clguba' Very nice new functionality in Py3k, but 2.x doesn't seem to have such a meth

Re: Python Fast I/o

2014-01-14 Thread Tim Chase
On 2014-01-14 05:50, Ayushi Dalmia wrote: > I need to write into a file for a project which will be evaluated > on the basis of time. What is the fastest way to write 200 Mb of > data, accumulated as a list into a file. > > Presently I am using this: > > with open('index.txt','w') as f: > f

Re: Printer list value problem

2014-01-14 Thread Tim Chase
On 2014-01-14 11:24, Mike wrote: > Hello, > I confudsed,need printer the value of list (this is reaer from > csv) . The reader is ok, but my problem is in the print moment > because printer only the last value. For example my csv is: > > [] > us...@example.com;user1;lastName;Name > us...@e

Re: dictionary with tuples

2014-01-14 Thread Tim Chase
On 2014-01-14 13:10, Igor Korot wrote: > Hi, ALL, > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> dict = {} > >>>

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Tim Chase
On 2014-01-15 01:27, Steven D'Aprano wrote: > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > > But reading Guido, I thin

Re: Python declarative

2014-01-15 Thread Tim Chase
On 2014-01-16 10:09, Chris Angelico wrote: > myWindow = Window( > title="Hello World", > children=[Button( > label="I'm a button", > onClick=exit > )] > ) This also solves the problem that **kwargs are just a dict, which is inherently unordered. So with the previo

Re: 'Straße' ('Strasse') and Python 2

2014-01-16 Thread Tim Chase
On 2014-01-16 14:07, Steven D'Aprano wrote: > The unicode type in Python 2.x is less-good because: > > - it is missing some functionality, e.g. casefold; Just for the record, str.casefold() wasn't added until 3.3, so earlier 3.x versions (such as the 3.2.3 that is the default python3 on Debian St

Re: Guessing the encoding from a BOM

2014-01-16 Thread Tim Chase
On 2014-01-17 05:06, Chris Angelico wrote: > > You might want to add the utf8 bom too: '\xEF\xBB\xBF'. > > I'd actually rather not. It would tempt people to pollute UTF-8 > files with a BOM, which is not necessary unless you are MS Notepad. If the intent is to just sniff and parse the file acco

Re: Python solve problem with string operation

2014-01-16 Thread Tim Chase
On 2014-01-17 00:24, Nac Temha wrote: > Hi everyone, > > I want to do operation with chars in the given string. Actually I > want to grouping the same chars. > > For example; > > input : "3443331123377" > operation-> (3)(44)()(333)(11)(2)(33)(77) > output: "34131237" > > How can

Re: Guessing the encoding from a BOM

2014-01-16 Thread Tim Chase
On 2014-01-17 11:14, Chris Angelico wrote: > UTF-8 specifies the byte order > as part of the protocol, so you don't need to mark it. You don't need to mark it when writing, but some idiots use it anyway. If you're sniffing a file for purposes of reading, you need to look for it and remove it from

Re: Python 3.x adoption

2014-01-17 Thread Tim Chase
On 2014-01-17 15:27, Grant Edwards wrote: > > What's wrong?... > > Python 2.7 still does everything 99% of us need to do, and we're too > lazy to switch. And in most distros, typing "python" invokes 2.x, and explicitly typing "python3" is almost 17% longer. We're a lazy bunch! :-) -tkc --

Re: Guessing the encoding from a BOM

2014-01-17 Thread Tim Chase
On 2014-01-17 09:10, Mark Lawrence wrote: > Slight aside, any chance of changing the subject of this thread, or > even ending the thread completely? Why? Every time I see it I > picture Inspector Clouseau, "A BOM!!!" :) In discussions regarding BOMs, I regularly get the "All your base" meme from

Re: Early retirement project?

2014-01-21 Thread Tim Chase
On 2014-01-21 00:00, xeysx...@gmail.com wrote: > Well, I retired early, and I guess now I've got some spare time to > learn about programming, which always seemed rather mysterious. I > am using an old mac as my main computer, and it runs os x 10.4 is > this too old? It fills my needs, and I am on

Re: import file without .py into another module

2014-01-21 Thread Tim Chase
On 2014-01-21 07:13, kevinber...@gmail.com wrote: >On Tuesday, January 21, 2014 10:06:16 AM UTC-5, MRAB wrote: >> configModuleObject = imp.load_source(fileName, filePath) >> >> imports the module and then binds it to the name >> configModuleObject, >> >> therefore: >> >> print configMod

Re: Separate Address number and name

2014-01-21 Thread Tim Chase
On 2014-01-22 02:46, John Gordon wrote: > > FarmID AddressNumAddressName > > 1 1067 Niagara Stone > > 2 4260 Mountainview > > 3 25Hunter > > 4 1091 Hutchinson > > > I have struggled with this for a while and know there must be a > > simple me

Re: problem with sqlite3: cannot use < in a SQL query with (?)

2014-01-22 Thread Tim Chase
On 2014-01-23 03:32, lgabiot wrote: > >>>cursor = conn.execute("SELECT filename, filepath FROM files > >>>WHERE > max_level<(?)", threshold) > that doesn't work (throw an exception) That last argument should be a tuple, so unless "threshold" is a tuple, you would want to make it sql = "S

Re: sqlite3 docbug (was problem with sqlite3)

2014-01-23 Thread Tim Chase
On 2014-01-23 05:43, Terry Reedy wrote: > A list instead of a tuple does work, but not an iterable, so > 'sequence'. In the OP's case using sqlite drivers, this is true. However, I maintain some old 2.4 code that uses a correspondingly ancient version of mx.ODBC which requires a tuple and raises

Re: Case insensitive exists()?

2014-01-23 Thread Tim Chase
On 2014-01-22 17:58, Larry Martell wrote: > I have the need to check for a files existence against a string, > but I need to do case-insensitively. I cannot efficiently get the > name of every file in the dir and compare each with my string using > lower(), as I have 100's of strings to check for,

Re: Initialise dictionary of dictionary

2014-01-23 Thread Tim Chase
On 2014-01-23 07:15, Ayushi Dalmia wrote: > I need to initialise a dictionary of dictionary with float values. > I do not know the size of the dictionary beforehand. How can we do > that in Python -- Either d = {} or, if you want from collections import defaultdict d = defaultdict(float)

Re: Initialise dictionary of dictionary

2014-01-23 Thread Tim Chase
On 2014-01-23 10:34, Dave Angel wrote: > Unsure of what the floats have to do with it. Perhaps you meant > float KEYS. using floats for keys can be dangerous, as small rounding errors in math can produce keys different enough that they're not found by an exact-match lookup. But yeah, the origin

Re: The potential for a Python 2.8.

2014-01-24 Thread Tim Chase
On 2014-01-24 19:56, Roy Smith wrote: > In article , > Grant Edwards wrote: > > > On 2014-01-24, Roy Smith wrote: > > > In article > > > , Chris > > > Angelico wrote: > > > > > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith > > >> wrote: > > >> >> Python 2.8j? > > >> > > > >> > You're imaginin

Re: Python with 3d cartoon

2014-01-26 Thread Tim Chase
On 2014-01-26 02:46, ngangsia akumbo wrote: > Is it possible to write cartoon with 3D images using python? > > If yes , please locate me some resources. thank Check out Blender which can be scripted using Python. -tkc -- https://mail.python.org/mailman/listinfo/python-list

Re: re Questions

2014-01-26 Thread Tim Chase
On 2014-01-26 12:15, Roy Smith wrote: > > The set [A-z] is equivalent to > > [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] > > I'm inclined to suggest the regex compiler should issue a warning > for this. > > I've never seen a character range other than A-Z, a-z, or 0-9. > Well,

Re: Lists inside dictionary and how to look for particular value

2014-01-26 Thread Tim Chase
On 2014-01-26 10:47, mick verdu wrote: > z={ 'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], > 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], > 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200'] } > > My solution: > > z=raw_input("Enter Host, Mac, ip and time") > t=z.split() > t[

Re: [newbie] copying identical list for a function argument

2014-02-03 Thread Tim Chase
On 2014-02-03 13:36, Jean Dupont wrote: > I have a list like this: > [1,2,3] > > The argument of my function should be a repeated version e.g. > [1,2,3],[1,2,3],[1,2,3],[1,2,3] (could be a different number of > times repeated also) > > what is the prefered method to realize this in Python? > > a

Re: Finding size of Variable

2014-02-04 Thread Tim Chase
On 2014-02-04 14:21, Dave Angel wrote: > To get the "total" size of a list of strings, try (untested): > > a = sys.getsizeof (mylist ) > for item in mylist: > a += sys.getsizeof (item) I always find this sort of accumulation weird (well, at least in Python; it's the *only* way in many other

Re: parse a csv file into a text file

2014-02-05 Thread Tim Chase
On 2014-02-05 16:10, Zhen Zhang wrote: > import csv > file = open('raw.csv') Asaf recommended using string methods to split the file. Keep doing what you're doing (using the csv module), as it attends to a lot of edge-cases that will trip you up otherwise. I learned this the hard way several yea

Re: parse a csv file into a text file

2014-02-05 Thread Tim Chase
On 2014-02-05 19:59, Asaf Las wrote: > On Thursday, February 6, 2014 2:46:04 AM UTC+2, Tim Chase wrote: > > On 2014-02-05 16:10, Zhen Zhang wrote: > > Asaf recommended using string methods to split the file. Keep > > doing what you're doing (using the csv module), as

Re: parse a csv file into a text file

2014-02-06 Thread Tim Chase
On 2014-02-06 17:40, Mark Lawrence wrote: > On 06/02/2014 14:02, Neil Cerutti wrote: > > > > You must open the file in binary mode, as that is what the csv > > module expects in Python 2.7. newline handling can be enscrewed > > if you forget. > > > > file = open('raw.csv', 'b') > > > > I've never

Re: parse a csv file into a text file

2014-02-06 Thread Tim Chase
[first, it looks like you're posting via Google Groups which annoyingly double-spaces everything in your reply. It's possible to work around this, but you might want to subscribe via email or an actual newsgroup client. You can read more at https://wiki.python.org/moin/GoogleGroupsPython ] On 201

Re: parse a csv file into a text file

2014-02-06 Thread Tim Chase
On 2014-02-06 18:34, Neil Cerutti wrote: > They do actually mention it. > > From: http://docs.python.org/2/library/csv.html > > If csvfile is a file object, it must be opened with > the ‘b’ flag on platforms where that makes a difference. > > So it's stipulated only for file objects on syst

Re: Question about `list.insert`

2014-02-06 Thread Tim Chase
On 2014-02-06 22:00, Roy Smith wrote: > > list does not promise better than O(1) behavior > > I'm not aware of any list implementations, in any language, that > promises better than O(1) behavior for any operations. Perhaps > there is O(j), where you just imagine the operation was performed?

Re: Sorting dictionary by datetime value

2014-02-08 Thread Tim Chase
On 2014-02-08 19:29, Chris Angelico wrote: > On Sat, Feb 8, 2014 at 7:25 PM, Igor Korot > wrote: > >> Try this: > >> > >> sorted_items = sorted(my_dict.keys(), key=my_dict.get) > > > > This code fail. > > Actually, it's a list of keys - notice that I changed > my_dict.items() into my_dict.keys()?

Re: What is the recommended python module for SQL database access?

2014-02-09 Thread Tim Chase
On 2014-02-09 22:00, Chris Angelico wrote: > On Sun, Feb 9, 2014 at 9:20 PM, Marcel Rodrigues > wrote: > > As Chris said, if your needs are simple, use SQLite back-end. > > It's probably already installed on your computer and Python has a > > nice interface to it in its standard library. > > Al

Re: Finding size of Variable

2014-02-10 Thread Tim Chase
On 2014-02-10 06:07, wxjmfa...@gmail.com wrote: > Python does not save memory at all. A str (unicode string) > uses less memory only - and only - because and when one uses > explicitly characters which are consuming less memory. > > Not only the memory gain is zero, Python falls back to the > wors

Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!)

2014-02-11 Thread Tim Chase
On 2014-02-11 06:30, Steven D'Aprano wrote: > You need to understand the difference between syntax and semantics. > This is invalid English syntax: > > "Cat mat on sat the." > > This is valid syntax, but semantically wrong: > > "The mat sat on the cat." > > This is both syntactically and semant

Re: Flag control variable

2014-02-11 Thread Tim Chase
On 2014-02-11 10:16, luke.gee...@gmail.com wrote: > when expandig the script to multiple calcs i got a problem > >>> a = 32 > >>> c = 51 > >>> sign = * > > File "", line 1 > sign = * >^ > SyntaxError: invalid syntax > > is there a way of adding * without quoting marks, because if

Re: Flag control variable

2014-02-11 Thread Tim Chase
On 2014-02-11 10:37, luke.gee...@gmail.com wrote: > command1 = "sudo mpg321 > 'http://translate.google.com/translate_tts?tl=en&q=%s_times%s_equals%s'" > % (a, b, sum) > > when using * i get > > Traceback (most recent call last): > File "./math+.py", line 6, in > b = int(sys.argv[3]) > V

Re: Flag control variable

2014-02-11 Thread Tim Chase
On 2014-02-11 11:06, luke.gee...@gmail.com wrote: > > > > command1 = "sudo mpg321 > > > > > > > > > > > > > > > 'http://translate.google.com/translate_tts?tl=en&q=%s_times%s_equals%s'" > > > > 1) PLEASE either stop using Google Groups or take the time to remove the superfluous

Re: Understanding Python from a PHP coder's perspective

2015-12-07 Thread Tim Chase
On 2015-12-08 10:09, Chris Angelico wrote: > All three are very different. > > 1) Process state. > > You start up a Python program, and it sits there waiting for a > request. You give it a request, and get back a response; it goes > back to waiting for a request. If you change a global variable,

Re: Understanding Python from a PHP coder's perspective

2015-12-07 Thread Tim Chase
On 2015-12-08 08:40, Chris Angelico wrote: > One advantage of this kind of setup is that your URLs don't depend > on your back end. I could replace all this with a Ruby on Rails > site, and nobody would notice the difference. I could put together > something using Node.js to replace the Ruby site,

Re: Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-22 Thread Tim Chase
On 2015-12-21 23:24, Jon Ribbens wrote: > That sounds a bit confused - if the *intention* of changing the > subject line is to create a new thread, then breaking the thread > is not "breaking threading" ;-) I'm pretty sure that the purpose is not to *break* the thread, but to suggest that the sub-

Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-24 Thread Tim Chase
On 2015-12-24 11:36, malitic...@gmail.com wrote: > it is a homework, but we are to figure out the solution first , all > we need is some guidance please and not to be spoon fed like many > thought Ah, with the intended interface as given by the tests, and the code you've already put together, you

Re: Python and multiple user access via super cool fancy website

2015-12-24 Thread Tim Chase
On 2015-12-24 14:39, Aaron Christensen wrote: > I am not sure if this is the correct venue for my question, but I'd > like to submit my question just in case. I am not a programmer but > I do have an incredible interest in it, so please excuse my lack of > understanding if my question isn't very t

Re: We will be moving to GitHub

2016-01-02 Thread Tim Chase
On 2016-01-02 17:43, Steven D'Aprano wrote: > Oh, and talking about DVCS: > > https://bitquabit.com/post/unorthodocs-abandon-your-dvcs-and-return-to-sanity/ The arguments there are pretty weak. Not working offline? I use that *ALL* *THE* *TIME*. Maybe the author lives some place where the main

Re: Trailing zeros of 100!

2016-01-02 Thread Tim Chase
On 2016-01-02 03:49, katye2...@gmail.com wrote: > I'm trying to write a python program to find how many trailing > zeros are in 100! (factorial of 100). I used factorial from the > math module, but my efforts to continue failed. Please help. Pretty easy to do with strings: from math import fact

Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Tim Chase
On 2016-01-05 20:38, Steven D'Aprano wrote: > On Tue, 5 Jan 2016 07:53 pm, Tony van der Hoff wrote: > > > Why would someone want to make 400 HTTP requests in a short time? > > For the same reason they want to make 400 HTTP requests over a long > time, except that they're in a hurry. > > Maybe th

Re: Fast pythonic way to process a huge integer list

2016-01-06 Thread Tim Chase
On 2016-01-06 18:36, high5stor...@gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to > process this list in 1,280 chunks of 128 integers? That's a modest list, far from huge. You have lots of options, but the following seems the most pythonic to me: # I don'

Re: Which Python editor has this feature?

2016-01-10 Thread Tim Chase
On 2016-01-10 17:59, jf...@ms4.hinet.net wrote: > It lets you jump between the current cursor position and the line > the upper level indentation start, something like the bracket > matching in C editor. Because of Python use indentation as its code > block mark, It might be helpful if we can jump

Re: Which Python editor has this feature?

2016-01-11 Thread Tim Chase
On 2016-01-11 03:08, jf...@ms4.hinet.net wrote: > Tim Chase at 2016/1/11 UTC+8 11:16:27AM wrote: > > :nnoremap Q '?^'.repeat(' ', > > (strlen(substitute(getline('.'), '\S.*', '', > > ''))-&sw)).'\S?e&

modifying parts of a urlparse.SplitResult

2016-01-12 Thread Tim Chase
I can successfully parse my URLs. However, I'd like to modify a part then reassemble them. However, like tuples, the parts appear to be unmodifiable >>> URL = 'http://foo/path1/path2/?fragment=foo' >>> import urlparse >>> u = urlparse.urlparse(URL) >>> u ParseResult(scheme='http', ne

Re: modifying parts of a urlparse.SplitResult

2016-01-12 Thread Tim Chase
On 2016-01-12 13:46, Peter Otten wrote: > Tim Chase wrote: > > >>> u = urlparse.urlsplit(URL) > > >>> lst = list(u) # can't manipulate the tuple directly > > >>> lst[3] = "bar=baz" # 3 = query-string index > > >>>

Re: Writing a stream of bytes

2016-01-15 Thread Tim Chase
On 2016-01-15 16:55, jmp wrote: > Hi pyple ! > > > I'd like to write a stream of bytes into a file. I'd like to use > the struct (instead of bytearray) module because I will have to > write more than bytes. > > let's say I want a file with 4 bytes in that order: > > 01 02 03 04 > > None of the

Re: Writing a stream of bytes

2016-01-15 Thread Tim Chase
[sorry, toddler on my lap clicked before I could type] > import struct > with open('toto', 'wb') as f: f.write(struct.pack('<4B', *[1,2,3,4])) This one does what you want. The problem resides in your check: > I always end up with the following bytes on file: > !hexdump toto > 000 0201 0403

Re: realtime output and csv files

2016-02-05 Thread Tim Chase
On 2016-02-05 17:57, Bernardo Sulzbach wrote: > CSVs is essentially text separated by commas, so you likely do not > need any library to write it "Just separating with ','" should work > if you are formatting them correctly. > https://mail.python.org/mailman/listinfo/python-list And even if you ha

Re: realtime output and csv files

2016-02-06 Thread Tim Chase
On 2016-02-06 02:53, Bernardo Sulzbach wrote: >> And even if you have things to escape or format correctly, the >> stdlib has a "csv" module that makes this trivially easy: >> > > I supposed it had one. Obviously, I've never used it myself, > otherwise I would be sure about its existence. Nice t

Re: A sets algorithm

2016-02-07 Thread Tim Chase
On 2016-02-07 21:46, Paulo da Silva wrote: > Suppose I have already a class MyFile that has an efficient method > (or operator) to compare two MyFile s for equality. > > What is the most efficient way to obtain all sets of equal files (of > course each set must have more than one file - all single

<    1   2   3   4   5   6   7   8   9   10   >