Re: .split() Qeustion
Le dimanche 18 août 2013 01:30:14 UTC+2, Gregory Ewing a écrit : wxjmfa...@gmail.com wrote: Na + Cl -- NaCl the chemist combines *one mole* of sodium and *one mole* of chlorine to get *one mole* of sodium chloride It's independent of the number of particles in a mole. The actual number chosen for the unit is arbitrary, but number of particles is still the central issue. The important thing is to have the *same* number of particles of Na and Cl. Weight only comes into it because it's totally impractical to count particles. And the particular number 6.02e23 is chosen because it happens to give a convenient relationship between number of particles and grams. If chemists had decided to use ounces instead, the number would be different. -- Greg The actual number chosen for the unit is arbitrary, but number of particles is still the central issue. No. The important thing is to have the *same* number of particles of Na and Cl. Yes. And it is precisely for that reason, a chemist works in mole arithetic. Same reaction as above Na + Cl -- NaCl in pseudo math, with n = number of elements in a mole. n * Na + n * Cl -- n * NaCl== n * (Na + Cl) -- n * NaCl == division by n Na + Cl -- NaCl for any n. The determination of n, the number of elements in a mole, is an indipendent and separate problem. (BTW, a very complicate task). jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Le vendredi 16 août 2013 15:23:37 UTC+2, Roy Smith a écrit : In article 2d88bc0f-fdcb-4685-87ed-c17998dd3...@googlegroups.com, wxjmfa...@gmail.com wrote: A chemist has to work and is always working in mole; as his balance can only measure a mass, the calculation mole - mass is always mandatory. That's because chemists are lazy. The recipe says, Add one mole of carbon atoms. So, does the chemist follow the recipe and count out 6.022 x 10^23 atoms like he's supposed to? No. He says, I don't have time for that. I'll just weigh out 12 grams. Good enough for government work. Sheesh. You don't understand the concept of mole. In this formal reaction Na + Cl -- NaCl the chemist combines *one mole* of sodium and *one mole* of chlorine to get *one mole* of sodium chloride (cooking salt). It's independent of the number of particles in a mole. It's not a question of laziness, the chemist can only weight 22.98 g of sodium to work with one mole of sodium, because the nature is like this. The work with relative quantities has a name: stoichiometry. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
I wrote: The recipe says, Add one mole of carbon atoms. So, does the chemist follow the recipe and count out 6.022 x 10^23 atoms like he's supposed to? No. He says, I don't have time for that. I'll just weigh out 12 grams. Good enough for government work. Sheesh. In article 8584caa1-1593-41ac-8e0c-4ac463991...@googlegroups.com, wxjmfa...@gmail.com wrote: You don't understand the concept of mole. You don't understand the concept of joke :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
wxjmfa...@gmail.com wrote: Na + Cl -- NaCl the chemist combines *one mole* of sodium and *one mole* of chlorine to get *one mole* of sodium chloride It's independent of the number of particles in a mole. The actual number chosen for the unit is arbitrary, but number of particles is still the central issue. The important thing is to have the *same* number of particles of Na and Cl. Weight only comes into it because it's totally impractical to count particles. And the particular number 6.02e23 is chosen because it happens to give a convenient relationship between number of particles and grams. If chemists had decided to use ounces instead, the number would be different. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: Not quite. A mole (abbreviation: mol) is a name for a specific number, like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. And I can't believe I still remember that value :-) Avogadro's Number is worth remembering, for mocking the pseudo-science of homeopathy URL:http://www.1023.org.uk/what-is-homeopathy.php. By knowing the scale of Avogadro's Limit – the maximum dilution of matter before one can confidently say the solution contains none of the original substance – one can look at the claims of homeopathy and confidently say that it can't contain anything effective. working-to-laugh-alt-med-out-of-the-world-ly yrs, -- \ “I'm having amnesia and déjà vu at the same time. I feel like | `\ I've forgotten this before sometime.” —Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
In article mailman.613.1376632775.1251.python-l...@python.org, Ben Finney ben+pyt...@benfinney.id.au wrote: Avogadro's Number is worth remembering, for mocking the pseudo-science of homeopathy URL:http://www.1023.org.uk/what-is-homeopathy.php. You have obviously never argued science with a homeopath if you believe that knowing Avogadro's number will in any way shake their faith. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
- A mole is an amount of matter measured in [kg] . The Avogadro's number can only be a dimensionless number, [1] . The Avogadro's constant is the Avogadro's number (of pieces or objects) per mol, [1 / mol]. A chemist has to work and is always working in mole; as his balance can only measure a mass, the calculation mole - mass is always mandatory. Why did I put this mole in the post scriptum? Because there is a tendency on this list to be extremely confused and to compare what is not comparable (eg. comparaison of mole and Python large number, number and radian, byte and unicode transformation unit). jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
In article 2d88bc0f-fdcb-4685-87ed-c17998dd3...@googlegroups.com, wxjmfa...@gmail.com wrote: A chemist has to work and is always working in mole; as his balance can only measure a mass, the calculation mole - mass is always mandatory. That's because chemists are lazy. The recipe says, Add one mole of carbon atoms. So, does the chemist follow the recipe and count out 6.022 x 10^23 atoms like he's supposed to? No. He says, I don't have time for that. I'll just weigh out 12 grams. Good enough for government work. Sheesh. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 2013-08-16, Roy Smith r...@panix.com wrote: In article mailman.613.1376632775.1251.python-l...@python.org, Ben Finney ben+pyt...@benfinney.id.au wrote: Avogadro's Number is worth remembering, for mocking the pseudo-science of homeopathy URL:http://www.1023.org.uk/what-is-homeopathy.php. You have obviously never argued science with a homeopath if you believe that knowing Avogadro's number will in any way shake their faith. He wasn't talking about arguing with a homeopath -- he was talking about mocking homeopathy. If you accept the premise of homeopathy having to do with the transferring of the essence or memory or whatever it's called, the fact that the final solution contains none of the original solute is irrelevant, and they will freely admit that none of the solute is actually present. It's all a complete and utter scam, of course. -- Grant Edwards grant.b.edwardsYow! I'm a nuclear at submarine under the gmail.compolar ice cap and I need a Kleenex! -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Friday 16 August 2013 10:07:12 Roy Smith did opine: In article 520da6d1$0$3$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). Not quite. A mole (abbreviation: mol) is a name for a specific number, like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. And I can't believe I still remember that value :-) I remember it as 6.022e23 :-) In my high school chemistry class, there was a wooden cube, about 1/2 meter on a side, sitting on the lecture desk in the front of the room. The only writing on it was 6.022 x 10^23. It sat there all year. The volume of the cube was that of 1 mole of an ideal gas at STP. A light-year, on the other hand, is a dimensional quantity. Whereas mole is dimensionless, light-year has dimensions of Length, and therefore the value depends on the units you measure in: 1 light-year: = 3.724697e+17 inches = 0.30660139 parsec = 9.4607305e+12 kilometres Hold your hands out in front of you, palms facing towards each other, one shoulder-width apart. That distance is about one light-nanosecond. Or a quite noticeable color shift when you are cutting coax cables for color phase matching, which we often had to do in an analog NTSC broadcast facility. Where a 1 degree shift, may or may not have been noticeable, was the cable equivalent of 7.7601420788892939683e-10 seconds, which was for the small foam cored cables used for such, with a Propagation Velocity of 0.78*C, only a very short length of cable. I'd have figured how much but I got lost pushing buttons in kcalc just now and came up with something I'd have to use a micrometer to measure. Its been close to 30 years since I had to do such calcs on a near daily basis. Your trivia factoid for the day, and I now return you to the regularly scheduled discussion going no where specifically. :-) Cheers, Gene -- There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order. -Ed Howdershelt (Author) My web page: http://coyoteden.dyndns-free.com:85/gene is up! My views http://www.armchairpatriot.com/What%20Has%20America%20Become.shtml I suppose that in a few hours I will sober up. That's such a sad thought. I think I'll have a few more drinks to prepare myself. A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Friday 16 August 2013 10:27:36 Dave Angel did opine: Roy Smith wrote: In article 520da6d1$0$3$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). Not quite. A mole (abbreviation: mol) is a name for a specific number, like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. And I can't believe I still remember that value :-) I remember it as 6.022e23 :-) In my high school chemistry class, there was a wooden cube, about 1/2 meter on a side, sitting on the lecture desk in the front of the room. The only writing on it was 6.022 x 10^23. It sat there all year. The volume of the cube was that of 1 mole of an ideal gas at STP. A light-year, on the other hand, is a dimensional quantity. Whereas mole is dimensionless, light-year has dimensions of Length, and therefore the value depends on the units you measure in: 1 light-year: = 3.724697e+17 inches = 0.30660139 parsec = 9.4607305e+12 kilometres Hold your hands out in front of you, palms facing towards each other, one shoulder-width apart. That distance is about one light-nanosecond. Narrow shoulders. I figure it just under a foot. I once attended a lecture by Grace Hopper where she handed out nanoseconds, pieces of wire about a foot long. She said that the beaurocrats were always asking how much is a nanosecond, and couldn't imagine what a billionth was like. So she gave them something physical. Chuckle. I always figured Grace Hopper had to have been a stand up comic in some previous life. She sure could translate the problem into something the paper pushers could grok. Cheers, Gene -- There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order. -Ed Howdershelt (Author) My web page: http://coyoteden.dyndns-free.com:85/gene is up! My views http://www.armchairpatriot.com/What%20Has%20America%20Become.shtml Nachman's Rule: When it comes to foreign food, the less authentic the better. -- Gerald Nachman A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Gene Heskett wrote: Where a 1 degree shift, may or may not have been noticeable, was the cable equivalent of 7.7601420788892939683e-10 seconds, which was for the small foam cored cables used for such, with a Propagation Velocity of 0.78*C, only a very short length of cable. I'd have figured how much but I got lost pushing buttons in kcalc Python says about 180mm. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Fri, 16 Aug 2013 05:27:49 +, Dave Angel wrote: I figure it just under a foot. I once attended a lecture by Grace Hopper where she handed out nanoseconds, pieces of wire about a foot long. Is that based on the speed of light in a vacuum, speed of light in copper, speed of electron drift in copper, speed of sound in copper? Or perhaps it was aluminium wire? :-) She said that the beaurocrats were always asking how much is a nanosecond, and couldn't imagine what a billionth was like. So she gave them something physical. Hmmm, given when Grace Hopper was active in the navy, I would have thought that the simplest way to imagine a billionth would be one dollar is a billionth of the US National Debt or one person is a billionth of the world's population. None of which really helps the typical person visualise a billionth, since the typical person can't really visualise a billion people or a billion dollars. I think a simple analogy that works is: the width of a single human hair is a billionth of 100 metres (or yards, for Americans). People can visualise 100 metres, and they can visualise a hair. No need to relate things to the speed of light, which most people cannot visualise, or the circumference of the earth, or the distance from New York to Tokyo, or from Venus to Mars at aphelion :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Sat, Aug 17, 2013 at 3:38 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Fri, 16 Aug 2013 05:27:49 +, Dave Angel wrote: I figure it just under a foot. I once attended a lecture by Grace Hopper where she handed out nanoseconds, pieces of wire about a foot long. Is that based on the speed of light in a vacuum, speed of light in copper, speed of electron drift in copper, speed of sound in copper? Or perhaps it was aluminium wire? :-) She said that the beaurocrats were always asking how much is a nanosecond, and couldn't imagine what a billionth was like. So she gave them something physical. I think a simple analogy that works is: the width of a single human hair is a billionth of 100 metres (or yards, for Americans). People can visualise 100 metres, and they can visualise a hair. Further information here: http://en.wikipedia.org/wiki/Grace_Hopper#Anecdotes It was specifically looking at satellite comms, and it's the speed of light through a vacuum (the ideal maximum speed of satellite communication signals). Check the Wiki page's footnotes for reliable references. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
.split() Qeustion
-- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Wed, 14 Aug 2013 13:05:50 -0400, random832 wrote: On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. Because high-level code isn't supposed to use the os module directly. Say what? My brain hurts. The os module is full of lots of platform independent goodies. It is the right way to split and combine pathnames, test environment variables, manipulate file permissions, and other useful tasks. Text-mode streams automatically convert newlines you write to them. Maybe they do, maybe they don't. It depends on whether Python is built with universal newline support, and what sort of text-mode stream you are using, and a bunch of other rules that make it a little more complicated than just automatically convert. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Le mercredi 14 août 2013 19:14:59 UTC+2, Chris Angelico a écrit : On Wed, Aug 14, 2013 at 6:05 PM, random...@fastmail.us wrote: On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. Because high-level code isn't supposed to use the os module directly. Text-mode streams automatically convert newlines you write to them. I'm always, and will still be, surprised by the number of hard coded decimal integers one can find in Python code, when the portable way to do it is to use ctypes and figure out whether your literals should be big-endian or little-endian, 32-bit or 64-bit, etc. Yet people continue to just put decimal literals in their code! It can't be portable. ChrisA -- As a stupid scientist, I have the habbit to compare things of the same nature with the same units. This *string* containing one *character* sys.getsizeof('a') 26 consumes 26 *bytes*. This *string* containing one *character* sys.getsizeof('\u2023') 40 consumes 40 *bytes*. and the difference is 40 [bytes] - 26 [bytes] = 14 [bytes] . — Python seems to consider os.linesep as a str. isinstance(os.linesep, str) True — PS A mole is not a number. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Joshua Landau jos...@landau.ws wrote: That's true with this example, but is: lines = [ Developments in high-speed rail, and high-speed, transport more generally, have historically been, impeded by the difficulties in managing friction, and air resistance, both of which become, substantial when vehicles approach high speeds., The vactrain concept eliminates these obstacles, by employing magnetically levitating trains in, tubes kept at a complete vacuum, allowing for, heoretical speeds of thousands of miles per, hour. The high cost of constructing such a system,, however, and the difficulty of maintaining a, vacuum over large distances, has prevented this, type of system from ever being built. The, Hyperloop can be viewed as a modified vactrain,, employing more cost-effective solutions to the, same problems the latter was designed to solve. ] really more readable than: lines = \ Developments in high-speed rail, and high-speed transport more generally, have historically been impeded by the difficulties in managing friction and air resistance, both of which become substantial when vehicles approach high speeds. The vactrain concept eliminates these obstacles by employing magnetically levitating trains in tubes kept at a complete vacuum, allowing for heoretical speeds of thousands of miles per hour. The high cost of constructing such a system, however, and the difficulty of maintaining a vacuum over large distances, has prevented this type of system from ever being built. The Hyperloop can be viewed as a modified vactrain, employing more cost-effective solutions to the same problems the latter was designed to solve. [1:-1].split(\n) ? I suppose the question really is whether the author of the second example really meant to start with the word 'evelopments'? If that was a mistake, then the first one is demonstrably less error prone. If it was intentional then the second one is definitely less readable. Either way I think you've proved that the first way of writing it is more readable. -- Duncan Booth -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
A technical ascpect of triple quoted strings is that the end of lines are not respected. import zzz zzz.__doc__ 'abc\ndef\n' with open('zzz.py', 'rb') as fo: ... r = fo.read() ... r b'abc\r\ndef\r\n\r\n' Now, one can argue... jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, Aug 15, 2013 at 10:46 AM, wxjmfa...@gmail.com wrote: A technical ascpect of triple quoted strings is that the end of lines are not respected. import zzz zzz.__doc__ 'abc\ndef\n' with open('zzz.py', 'rb') as fo: ... r = fo.read() ... r b'abc\r\ndef\r\n\r\n' Now, one can argue... Actually, they are respected. Triple-quoted strings are parsed after the file is read in, and newline handling is dealt with at an earlier level, same as encodings are. You wouldn't expect that string to retain information about the source file's encoding, and nor do you expect it to retain the source file's newline style. A newline is represented in the file on disk as \r\n or \n (or something else, even), and in the string as \n. It's that simple. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, 15 Aug 2013 02:46:20 -0700, wxjmfauth wrote: A technical ascpect of triple quoted strings is that the end of lines are not respected. import zzz zzz.__doc__ 'abc\ndef\n' You are misinterpreting what you are seeing. You are not reading lines of text from a file. You are importing a module, and they accessing its __doc__ attribute. The relationship between the module object and text from a file is tenuous, at best: - the module's file could use \n line endings, or \r, or \r\n, or even something else, depending on the platform; - the module might be a compiled .pyc file, and there are no lines of text to read, just byte code; - or a .dll or .so library, again, no lines of text, just compiled code; - or there might not even be a file, like the sys module, which is entirely built into the interpreter; - or it might not even be a module object, you can put anything into sys.module. It might be an instance with docstrings computed on the fly. So you can't conclude *anything* about text files from the fact that module docstrings typically contain only \n rather than \r\n line endings. Modules are not necessarily text files, and even when they are, once you import them, what you get is *not text*, but Python objects. with open('zzz.py', 'rb') as fo: ... r = fo.read() ... r b'abc\r\ndef\r\n\r\n' And again, you are misinterpreting what you are seeing. By opening the file in binary mode, you are instructing Python to treat it as binary bytes, and return *exactly* what is stored on disk. If you opened the file in text mode, you would (likely, but not necessarily) get a very different result: the string would contain only \n line endings. Python is not a low-level language like C. If you expect it to behave like a low-level language like C, you will be confused and upset. But to prove that you are mistaken, we can do this: py s = Triple-quote string\r ... containing carriage-return+newline line\r ... endings. py s 'Triple-quote string\r\ncontaining carriage-return+newline line\r \nendings.' -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
I perfectly knows what Python does. I missinterpreting nothing. I opened my example in binary mode just to show the real endings. It still remains the ... has its owns EOL and one has to be aware of it. No more, no less. (... and tokenize.py is funny) jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
wxjmfa...@gmail.com writes: As a stupid scientist, I have the habbit to compare things of the same nature with the same units. This *string* containing one *character* sys.getsizeof('a') 26 consumes 26 *bytes*. I'm not an expert in stupid science, and I fail to see the common nature of the stuff you are comparing. Strings are not characters, and neither the latter are bytes. Anyway, trying to apply the same stupid science, I notice a much more amazing fact: sys.getsizeof(True) 24 Does Python really needs twentyfour bytes to store a *single* bit of information?? Wow, since by definition a byte contains eight bits, there's a factor of 192... what a shame! :-) — Python seems to consider os.linesep as a str. isinstance(os.linesep, str) True Yes, I bet in stupid languages that would be either a single character, or a tuple of two or more characters, much more usable and compact. — PS A mole is not a number. Oh, nice to know. And OOC, what is a mole in your stupid science? OTOH, WTF does that matter in current thread and with Python in general? ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 15/08/2013 15:38, Lele Gaifax wrote: wxjmfa...@gmail.com writes: As a stupid scientist, I have the habbit to compare things of the same nature with the same units. This *string* containing one *character* sys.getsizeof('a') 26 consumes 26 *bytes*. I'm not an expert in stupid science, and I fail to see the common nature of the stuff you are comparing. Strings are not characters, and neither the latter are bytes. Anyway, trying to apply the same stupid science, I notice a much more amazing fact: sys.getsizeof(True) 24 Does Python really needs twentyfour bytes to store a *single* bit of information?? Wow, since by definition a byte contains eight bits, there's a factor of 192... what a shame! :-) — Python seems to consider os.linesep as a str. isinstance(os.linesep, str) True Yes, I bet in stupid languages that would be either a single character, or a tuple of two or more characters, much more usable and compact. — PS A mole is not a number. Oh, nice to know. And OOC, what is a mole in your stupid science? OTOH, WTF does that matter in current thread and with Python in general? A mole is a term from chemistry: http://en.wikipedia.org/wiki/Mole_%28unit%29 but I have no idea how it relates to Python or even to computers in general. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
MRAB pyt...@mrabarnett.plus.com writes: On 15/08/2013 15:38, Lele Gaifax wrote: wxjmfa...@gmail.com writes: PS A mole is not a number. Oh, nice to know. And OOC, what is a mole in your stupid science? OTOH, WTF does that matter in current thread and with Python in general? A mole is a term from chemistry: http://en.wikipedia.org/wiki/Mole_%28unit%29 Yes, I know that, but AFAIU, there is a closer correlation between a mole and a number than between a string and the number of bytes an arbitrary computer [language] needs to store it. It did not come out as funny as I meant :) ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, Aug 15, 2013 at 4:30 PM, Lele Gaifax l...@metapensiero.it wrote: MRAB pyt...@mrabarnett.plus.com writes: On 15/08/2013 15:38, Lele Gaifax wrote: wxjmfa...@gmail.com writes: PS A mole is not a number. Oh, nice to know. And OOC, what is a mole in your stupid science? OTOH, WTF does that matter in current thread and with Python in general? A mole is a term from chemistry: http://en.wikipedia.org/wiki/Mole_%28unit%29 Yes, I know that, but AFAIU, there is a closer correlation between a mole and a number than between a string and the number of bytes an arbitrary computer [language] needs to store it. It did not come out as funny as I meant :) A mole is as much a number (6e23) as the light year is a number (9.5e15). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). A mole is a number. A light year is a unit. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote: On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). A mole is a number. A light year is a unit. A mole is an amount of something. Avogadro's Number is a number, which is what I was hinting at :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 15 August 2013 19:28, Chris Angelico ros...@gmail.com wrote: On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote: On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). A mole is a number. A light year is a unit. A mole is an amount of something. Avogadro's Number is a number, which is what I was hinting at :) I stand corrected. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 8/15/2013 2:28 PM, Chris Angelico wrote: On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote: On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). A mole is a number. A light year is a unit. A mole is an amount of something. Avogadro's Number is a number, which is what I was hinting at :) The unit for 'mole' is 'ion', 'atom', or 'molecule', as appropriate for the 'something'. In other words, the units are the reacting input units and resulting output units in a particular chemical reaction. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Terry Reedy wrote: On 8/15/2013 2:28 PM, Chris Angelico wrote: On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote: On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). A mole is a number. A light year is a unit. A mole is an amount of something. Avogadro's Number is a number, which is what I was hinting at :) The unit for 'mole' is 'ion', 'atom', or 'molecule', as appropriate for the 'something'. In other words, the units are the reacting input units and resulting output units in a particular chemical reaction. To expand a little on that, the unit of amount of something is a gram mole, which is 6.2 **23 grams times the molecular (or atomic) weight. My dad (research chemist) used to have to order supplies for his lab in ton moles, and he used some very small multipliers, since he usually needed a kilogram or less in his lab. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). Not quite. A mole (abbreviation: mol) is a name for a specific number, like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. And I can't believe I still remember that value :-) It's normally used only for atoms, ions or molecules, but in principle you could talk about anything. E.g. the population of the world is a mere 1.2e-14 mol. A light-year, on the other hand, is a dimensional quantity. Whereas mole is dimensionless, light-year has dimensions of Length, and therefore the value depends on the units you measure in: 1 light-year: = 3.724697e+17 inches = 0.30660139 parsec = 9.4607305e+12 kilometres etc. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, 15 Aug 2013 19:28:46 +0100, Chris Angelico wrote: On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote: On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). A mole is a number. A light year is a unit. A mole is an amount of something. Avogadro's Number is a number, which is what I was hinting at :) Would you consider a dozen to be a number? Normally we use dozen only in reference to a dozen of something, not as an abstract pure number, but it's still a number in a way that light-year (or mile, or gram, or second) is not. Mole is like dozen. Light-year is like mile. And Avagadro's Number is like twelve, only a bit bigger :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, 15 Aug 2013 17:40:43 -0400, Terry Reedy wrote: On 8/15/2013 2:28 PM, Chris Angelico wrote: On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote: On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). A mole is a number. A light year is a unit. A mole is an amount of something. Avogadro's Number is a number, which is what I was hinting at :) The unit for 'mole' is 'ion', 'atom', or 'molecule', as appropriate for the 'something'. In other words, the units are the reacting input units and resulting output units in a particular chemical reaction. Careful about the use of the word unit, you're likely to confuse people into thinking atom is a unit of measurement like inches, seconds, grams or ohms. Naturally when dealing with moles of substance you have to take into account the kind of substance. In much the same way it makes a difference whether you are catering for a dozen people, a dozen couples, or a dozen football teams, a mole of oxygen molecules is not the same as a mole of oxygen atoms. But it's still the same number of things in each case, only the thing differs. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
In article 520da6d1$0$3$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). Not quite. A mole (abbreviation: mol) is a name for a specific number, like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. And I can't believe I still remember that value :-) I remember it as 6.022e23 :-) In my high school chemistry class, there was a wooden cube, about 1/2 meter on a side, sitting on the lecture desk in the front of the room. The only writing on it was 6.022 x 10^23. It sat there all year. The volume of the cube was that of 1 mole of an ideal gas at STP. A light-year, on the other hand, is a dimensional quantity. Whereas mole is dimensionless, light-year has dimensions of Length, and therefore the value depends on the units you measure in: 1 light-year: = 3.724697e+17 inches = 0.30660139 parsec = 9.4607305e+12 kilometres Hold your hands out in front of you, palms facing towards each other, one shoulder-width apart. That distance is about one light-nanosecond. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Thu, 15 Aug 2013 22:56:57 +, Dave Angel wrote: To expand a little on that, the unit of amount of something is a gram mole, which is 6.2 **23 grams times the molecular (or atomic) weight. The unit of amount of substance is mole. Gram-mole is an unfortunate synonym for mole. Unfortunate, because it looks like it should have dimensions of Mass, but it is actually a dimensionless number, and exactly equal to mole. As usual, we can blame the damn engineers and their sloppy, ad-hoc thinking for abominations like this: http://web.utk.edu/~dad/mole.html Also, you're quoting Avogadro's Constant incorrectly: it's 6.02e23, or if you prefer, 6.02*10**23, not 6.2**23, which is a factor of about 358581 too small. My dad (research chemist) used to have to order supplies for his lab in ton moles, and he used some very small multipliers, since he usually needed a kilogram or less in his lab. That's just sad. The supplier won't be counting out individual molecules, they'll be putting it on a scale and weighing it. So your dad had to convert the desired weight into a ridiculously impractical unit to place the order, and the supplier no doubt had to convert that unit back into mass in order to weigh it out and supply it. If you want a kilogram of X, why not order a kilogram of X, instead of converting it into megamol? Sigh, I know the answer to that question. We've always done it this way. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Fri, 16 Aug 2013 04:39:16 +, Steven D'Aprano wrote: On Thu, 15 Aug 2013 22:56:57 +, Dave Angel wrote: To expand a little on that, the unit of amount of something is a gram mole, which is 6.2 **23 grams times the molecular (or atomic) weight. The unit of amount of substance is mole. Gram-mole is an unfortunate synonym for mole. Oops, dropped a word there... The *SI unit* of amount of substance. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Roy Smith wrote: In article 520da6d1$0$3$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote: A mole is as much a number (6e23) as the light year is a number (9.5e15). Not quite. A mole (abbreviation: mol) is a name for a specific number, like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. And I can't believe I still remember that value :-) I remember it as 6.022e23 :-) In my high school chemistry class, there was a wooden cube, about 1/2 meter on a side, sitting on the lecture desk in the front of the room. The only writing on it was 6.022 x 10^23. It sat there all year. The volume of the cube was that of 1 mole of an ideal gas at STP. A light-year, on the other hand, is a dimensional quantity. Whereas mole is dimensionless, light-year has dimensions of Length, and therefore the value depends on the units you measure in: 1 light-year: = 3.724697e+17 inches = 0.30660139 parsec = 9.4607305e+12 kilometres Hold your hands out in front of you, palms facing towards each other, one shoulder-width apart. That distance is about one light-nanosecond. Narrow shoulders. I figure it just under a foot. I once attended a lecture by Grace Hopper where she handed out nanoseconds, pieces of wire about a foot long. She said that the beaurocrats were always asking how much is a nanosecond, and couldn't imagine what a billionth was like. So she gave them something physical. -- Signature file not found -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Tue, 13 Aug 2013 22:12:56 -0700, Gary Herron wrote: On 08/13/2013 09:51 PM, eschneide...@comcast.net wrote: How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) Eric I think you are referring to this: pie = 'keylime peach apple cherry pecan'.split() While it's easier to type, and does save a few characters, I think the original list is clearer to a reader of your program. Gary Herron I would agree with the last statement. Please write list definitions as lists rather than taking a short-cut to save a few key presses -- Accuracy, n.: The vice of being right -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 14 August 2013 09:30, Alister alister.w...@ntlworld.com wrote: On Tue, 13 Aug 2013 22:12:56 -0700, Gary Herron wrote: On 08/13/2013 09:51 PM, eschneide...@comcast.net wrote: How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) Eric I think you are referring to this: pie = 'keylime peach apple cherry pecan'.split() While it's easier to type, and does save a few characters, I think the original list is clearer to a reader of your program. Gary Herron I would agree with the last statement. Please write list definitions as lists rather than taking a short-cut to save a few key presses That's true with this example, but is: lines = [ Developments in high-speed rail, and high-speed, transport more generally, have historically been, impeded by the difficulties in managing friction, and air resistance, both of which become, substantial when vehicles approach high speeds., The vactrain concept eliminates these obstacles, by employing magnetically levitating trains in, tubes kept at a complete vacuum, allowing for, heoretical speeds of thousands of miles per, hour. The high cost of constructing such a system,, however, and the difficulty of maintaining a, vacuum over large distances, has prevented this, type of system from ever being built. The, Hyperloop can be viewed as a modified vactrain,, employing more cost-effective solutions to the, same problems the latter was designed to solve. ] really more readable than: lines = \ Developments in high-speed rail, and high-speed transport more generally, have historically been impeded by the difficulties in managing friction and air resistance, both of which become substantial when vehicles approach high speeds. The vactrain concept eliminates these obstacles by employing magnetically levitating trains in tubes kept at a complete vacuum, allowing for heoretical speeds of thousands of miles per hour. The high cost of constructing such a system, however, and the difficulty of maintaining a vacuum over large distances, has prevented this type of system from ever being built. The Hyperloop can be viewed as a modified vactrain, employing more cost-effective solutions to the same problems the latter was designed to solve. [1:-1].split(\n) ? Additionally,namedtuple has already set the precedence for this kind of thing. Finally, a simple extension or a decent editor should make it trivial to convert between the forms, so you can write the shorter way and convert on-the-fly. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Joshua Landau wrote: On 14 August 2013 09:30, Alister alister.w...@ntlworld.com wrote: On Tue, 13 Aug 2013 22:12:56 -0700, Gary Herron wrote: On 08/13/2013 09:51 PM, eschneide...@comcast.net wrote: How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) Eric I think you are referring to this: pie = 'keylime peach apple cherry pecan'.split() While it's easier to type, and does save a few characters, I think the original list is clearer to a reader of your program. Gary Herron I would agree with the last statement. Please write list definitions as lists rather than taking a short-cut to save a few key presses That's true with this example, but is: lines = [ Developments in high-speed rail, and high-speed, ... same problems the latter was designed to solve. ] really more readable than: lines = \ Developments in high-speed rail, and high-speed ... same problems the latter was designed to solve. [1:-1].split(\n) ? It's definitely more correct -- unless you meant to strip the D from the first line ;) I would use lines = \ Developments in high-speed rail, and high-speed ... same problems the latter was designed to solve. .splitlines() -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 14 August 2013 12:45, Peter Otten __pete...@web.de wrote: Joshua Landau wrote: On 14 August 2013 09:30, Alister alister.w...@ntlworld.com wrote: I would agree with the last statement. Please write list definitions as lists rather than taking a short-cut to save a few key presses That's true with this example, but is: lines = [ Developments in high-speed rail, and high-speed, ... same problems the latter was designed to solve. ] really more readable than: lines = \ Developments in high-speed rail, and high-speed ... same problems the latter was designed to solve. [1:-1].split(\n) ? It's definitely more correct -- unless you meant to strip the D from the first line ;) I would use lines = \ Developments in high-speed rail, and high-speed ... same problems the latter was designed to solve. .splitlines() Thanks, I didn't actually know about .splitlines()! -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Wed, 14 Aug 2013 11:31:01 +0100, Joshua Landau wrote: On 14 August 2013 09:30, Alister alister.w...@ntlworld.com wrote: On Tue, 13 Aug 2013 22:12:56 -0700, Gary Herron wrote: On 08/13/2013 09:51 PM, eschneide...@comcast.net wrote: How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) Eric I think you are referring to this: pie = 'keylime peach apple cherry pecan'.split() While it's easier to type, and does save a few characters, I think the original list is clearer to a reader of your program. Gary Herron I would agree with the last statement. Please write list definitions as lists rather than taking a short-cut to save a few key presses That's true with this example, but is: lines = [ Developments in high-speed rail, and high-speed, transport more generally, have historically been, impeded by the difficulties in managing friction, and air resistance, both of which become, substantial when vehicles approach high speeds., The vactrain concept eliminates these obstacles, by employing magnetically levitating trains in, tubes kept at a complete vacuum, allowing for, heoretical speeds of thousands of miles per, hour. The high cost of constructing such a system,, however, and the difficulty of maintaining a, vacuum over large distances, has prevented this, type of system from ever being built. The, Hyperloop can be viewed as a modified vactrain,, employing more cost-effective solutions to the, same problems the latter was designed to solve. ] really more readable than: lines = \ Developments in high-speed rail, and high-speed transport more generally, have historically been impeded by the difficulties in managing friction and air resistance, both of which become substantial when vehicles approach high speeds. The vactrain concept eliminates these obstacles by employing magnetically levitating trains in tubes kept at a complete vacuum, allowing for heoretical speeds of thousands of miles per hour. The high cost of constructing such a system, however, and the difficulty of maintaining a vacuum over large distances, has prevented this type of system from ever being built. The Hyperloop can be viewed as a modified vactrain, employing more cost-effective solutions to the same problems the latter was designed to solve. [1:-1].split(\n) ? Yes, because I can see at the start that a list is being created can skip over the data top the next line of code. I could easily miss the .split() at the end of the string deffinition. -- It ain't over until it's over. -- Casey Stengel -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Le mercredi 14 août 2013 13:55:23 UTC+2, Joshua Landau a écrit : On 14 August 2013 12:45, Peter Otten __pete...@web.de wrote: Joshua Landau wrote: On 14 August 2013 09:30, Alister alister.w...@ntlworld.com wrote: I would agree with the last statement. Please write list definitions as lists rather than taking a short-cut to save a few key presses That's true with this example, but is: lines = [ Developments in high-speed rail, and high-speed, ... same problems the latter was designed to solve. ] really more readable than: lines = \ Developments in high-speed rail, and high-speed ... same problems the latter was designed to solve. [1:-1].split(\n) ? It's definitely more correct -- unless you meant to strip the D from the first line ;) I would use lines = \ Developments in high-speed rail, and high-speed ... same problems the latter was designed to solve. .splitlines() Thanks, I didn't actually know about .splitlines()! a = ['==\r**', '==\n**', '==\r\n**', '==\u0085**', '==\u000b**', '==\u000c**', '==\u2028**', '==\u2029**'] for e in a: print(e.splitlines()) ['==', '**'] ['==', '**'] ['==', '**'] ['==', '**'] ['==', '**'] ['==', '**'] ['==', '**'] ['==', '**'] Do not confuse these NLF's (new line functions) in the Unicode terminology, with the end of line *symbols* (pilcrow, \u2424, ...) I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. Because high-level code isn't supposed to use the os module directly. Text-mode streams automatically convert newlines you write to them. -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Wed, Aug 14, 2013 at 6:05 PM, random...@fastmail.us wrote: On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. Because high-level code isn't supposed to use the os module directly. Text-mode streams automatically convert newlines you write to them. I'm always, and will still be, surprised by the number of hard coded decimal integers one can find in Python code, when the portable way to do it is to use ctypes and figure out whether your literals should be big-endian or little-endian, 32-bit or 64-bit, etc. Yet people continue to just put decimal literals in their code! It can't be portable. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 2013-08-14 18:14, Chris Angelico wrote: On Wed, Aug 14, 2013 at 6:05 PM, random...@fastmail.us wrote: On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. Because high-level code isn't supposed to use the os module directly. Text-mode streams automatically convert newlines you write to them. I'm always, and will still be, surprised by the number of hard coded decimal integers one can find in Python code, when the portable way to do it is to use ctypes and figure out whether your literals should be big-endian or little-endian, 32-bit or 64-bit, etc. Yet people continue to just put decimal literals in their code! It can't be portable. No, no, no...you want from sys.platform.integers import 0, 1, 2, 3, 14, 42 to be portable against endian'ness and bit-width. Granted, one might confuse them with regular numeric literals, so it would be best to clarify them by namespace: import sys answer_to_life = sys.platform.integers.42 print(sum(range(sys.platform.integers.0, sys.platform.integers.14))) That way you ensure platform independence, and *much* clearer! ;-) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Wed, Aug 14, 2013 at 12:05 PM, random...@fastmail.us wrote: Because high-level code isn't supposed to use the os module directly. That seems a bit extreme. One would hope that Guido and the rest of the crew created the os module so people would use it instead of resorting to other lower level hacks. A quick find/grep of my own code suggests that I import os more than sys. I use it mostly for os.path.* and os.environ. I'm not sure there's a higher level way to access them without putting more layers between your code and those objects, which code would obviously have to call them anyway. Did I just misread your comment? Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On Wed, Aug 14, 2013 at 6:29 PM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-08-14 18:14, Chris Angelico wrote: On Wed, Aug 14, 2013 at 6:05 PM, random...@fastmail.us wrote: On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. Because high-level code isn't supposed to use the os module directly. Text-mode streams automatically convert newlines you write to them. I'm always, and will still be, surprised by the number of hard coded decimal integers one can find in Python code, when the portable way to do it is to use ctypes and figure out whether your literals should be big-endian or little-endian, 32-bit or 64-bit, etc. Yet people continue to just put decimal literals in their code! It can't be portable. No, no, no...you want from sys.platform.integers import 0, 1, 2, 3, 14, 42 to be portable against endian'ness and bit-width. Oh! I didn't know about sys.platform.integers. All this time I've been doing it manually, usually copying and pasting a block of integer definitions from the re module. (I used to copy them from adamant.princess.ida but some of them were buggy. 2+2 made 5, or 3, or 7, or 25, depending on need.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 8/14/2013 1:05 PM, random...@fastmail.us wrote: On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: I'm always and still be suprised by the number of hard coded '\n' one can find in Python code when the portable (here win) os.linesep '\r\n' exists. Because high-level code isn't supposed to use the os module directly. This is a bit extreme, but definitely true for os.linesep and *much* of os other than os.path and maybe os.environ. Text-mode streams automatically convert newlines you write to them. By default, any possible linesep to \n when reading files;, \n to os.linesep when writing. Windows is the only major OS for which os.linesep is not \n. The full details, from the builtin 'open' entry: newline controls how universal newlines mode works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It works as follows: When reading input from the stream, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. When writing output to the stream, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '' or '\n', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
.split() Qeustion
How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) Eric -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
On 08/13/2013 09:51 PM, eschneide...@comcast.net wrote: How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) Eric I think you are referring to this: pie = 'keylime peach apple cherry pecan'.split() While it's easier to type, and does save a few characters, I think the original list is clearer to a reader of your program. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
eschneide...@comcast.net wrote: How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) I can't make any sense out of the first sentence. But maybe I can guess what you're looking for. The split() method is indeed a method of the str class. It takes an optional argument for the separator character. By default it uses whitespace. So if you're trying to specify a series of items, none of which contain any whitespace, you can readily use split to build your list: pie = keylime peach apple cherry pecan.split() However, there'd be no way to specify an item called chocolate marshmallow. If you need to include whitespace in any item, then you'd have to use some other separator, like a comma: pie = keylime,chocolate marshmallow,peach,apple,cherry, pecan.split(,) -- Signature file not found -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
Hi, How can I use the '.split()' method (am I right in calling it a method?) The .split() is a method in Python which comes as in built method for String objects in Python. Any string defined in python will have the ability to call this function. var = 'Hello how r u?' dir(var) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] var.split() ['Hello', 'how', 'r', 'u?'] writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) If you are talking about having predefined list pie with limited elements like above it is ok to code them straightaway with apostrophes and others will know that it is a predefined list. Suppose if the elements in list come as a line in a file or is a string, it will be better to use split() method and form a list. I hope Gary has provided the example for the same. pie = 'keylime peach apple cherry pecan'.split() I hope this clarifies your doubt. Regards, Krishnan On Tue, Aug 13, 2013 at 9:51 PM, eschneide...@comcast.net wrote: How can I use the '.split()' method (am I right in calling it a method?) without instead of writing each comma between words in the pie list in the following code? Also, is there a way to use .split instead of typing the apostrophes? Thank you. import random pie=['keylime', 'peach', 'apple', 'cherry', 'pecan'] print(random.choice(pie)) Eric -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: .split() Qeustion
It's obvious that the word 'without' in my first sentence was meant to be ommited, and it's a simple question. Thank Gary! -- http://mail.python.org/mailman/listinfo/python-list