[Tutor] object size in python is in what units?

2013-07-23 Thread Jim Mooney
I've noticed that when I create a number of objects from a class, one after
another, they're at different IDs, but the IDs all appear to be
equidistant, so that they all appear to have the same size. But what does
that size represent? is it bytes? ie - if I run this over and over I get
different id numbers but they are always 40 apart. Or is that distance
machine-specific as to units?:

#Using Python 2.7 on Win 7
from __future__ import division, print_function

class Kronk:
def __init__(self, zar):
self.zar = zar
def getzar(self):
return self.zar
def getself(self):
return id(self)

lardKronk = Kronk('ziggle')
newKronk = Kronk('barf')
budKronk = Kronk('baloney')

print(lardKronk.getzar())
print(newKronk.getzar())
print(budKronk.getzar())

print(lardKronk.getself())
print(newKronk.getself())
print(budKronk.getself())

'''result:
ziggle
barf
baloney
41599624 - different results for each run but always 40 apart
41599664
41599704
'''
-- 
Jim

When I was young dad told me if a moth fluttered onto my sleeping lips at
night
it would suck out my soul.

Dad was such a kidder.

But I still flee from moths.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] close, but no cigar

2013-07-23 Thread Steven D'Aprano

On 23/07/13 09:39, Marc Tompkins wrote:

On Mon, Jul 22, 2013 at 3:22 PM, Jim Mooney wrote:


On 22 July 2013 14:11, Marc Tompkins  wrote:



One way to deal with this is to specify an encoding:
 newchar = char.decode('cp437').encode('utf-8')



Works fine, but I decided to add a dos graphics dash to the existing dash
to expand the tree
visually. Except I got a complaint from IDLE that I should add this:

# -*- coding: utf-8 -*-

Will that always work? Setting coding in a comment? Or am I looking at a
Linux hash line?



I speak under correction here, but:  what you're setting there is the
encoding for the script file itself (and - the real point here - any
strings you specify, without explicit encoding, inside the script), NOT the
default encoding that Python is going to use while executing your script.
Unless I'm very much mistaken, Python will still use the default encoding
('ascii' in your case) when reading strings from external files.



Correct. The encoding declaration ONLY tells Python how to read the script. 
Remember, source code is text, but has to be stored on disk as bytes. If you 
only use ASCII characters, pretty much every program will agree what the bytes 
represent (since IBM mainframes using EBCDIC are pretty rare, and few programs 
expect double-byte encodings). But if you include non-ASCII characters, your 
text editor has to convert them to bytes. How does it do so? Nearly every 
editor is different, a plain text file doesn't have any way of storing metadata 
such as the encoding. Contrast this to things like JPEG files, which can store 
metadata like the camera you used to take the photo.

So, some programmer's editors have taken up the convention of using so-called "mode 
lines" to record editor settings as comments in source code, usually in the first 
couple or last couple of lines. Especially on Linux systems, Emacs and Vim uses 
frequently include such mode lines.

Python stole this idea from them. If the first or second line in the source code file is 
a comment containing something like "encoding = SPAM", then Python will read 
that source code using encoding SPAM. The form shown above

-*- coding: utf-8 -*-

is copied from Emacs. Python is pretty flexible though.

However, the encoding must be a known encoding (naturally), and the comment 
must be in the first or second line. You can't use it anywhere else. Well, you 
actually can, since it is a comment, but it will have no effect anywhere else.


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Hugo Arts
On Tue, Jul 23, 2013 at 9:09 AM, Jim Mooney wrote:

> I've noticed that when I create a number of objects from a class, one
> after another, they're at different IDs, but the IDs all appear to be
> equidistant, so that they all appear to have the same size. But what does
> that size represent? is it bytes? ie - if I run this over and over I get
> different id numbers but they are always 40 apart. Or is that distance
> machine-specific as to units?:
>
>
In Python, the id is just a number that identifies the object. You can't
count on it to represent object size, or anything else for that matter. The
only requirement for python implementations is that different objects can
not have the same id.

The CPython implementation uses the memory address of the object as its id
because it's simple and satisfies the above requirement. Still, i'd say
it's very unsafe to try to infer object sizes from this. It depends on how
memory addresses work on your machine, what type of memory allocator is
used and how much overhead it has, and many more factors. Furthermore,
other python implementations (I believe Jython and IronPython among them)
do not even use memory addresses as id numbers, but simply assign
consecutive integers to each created object.

In general, relying on the id number to tell you anything other than
whether two variables point to the same object is highly unreliable at best
and impossible in the general case.

HTH,
Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Steven D'Aprano

On 23/07/13 17:09, Jim Mooney wrote:

I've noticed that when I create a number of objects from a class, one after
another, they're at different IDs, but the IDs all appear to be
equidistant, so that they all appear to have the same size. But what does
that size represent? is it bytes?


No no no, a thousand times no!!! IDs are just numeric IDs, that is all, like 
your social security number or driver's licence number. Don't think of them as 
having any meaning at all, except that they are unique during the lifetime of 
the object.

Some Python implementations never reuse IDs, and they are numbered 
consecutively. IronPython numbers them from 40 (if memory serves me right), so 
you get 40, 41, 42, 43, ... while Jython numbers them consecutively from 1, 2, 
3, ... PyPy does something similar.

CPython does reuse IDs, and uses the memory address of the base of the object, 
as reported by the operating system, which leads to annoying people saying that 
id() returns the address of the object. This is WRONG. It does not. id() 
returns an arbitrary ID number.



ie - if I run this over and over I get
different id numbers but they are always 40 apart. Or is that distance
machine-specific as to units?:


Yes. It depends on whether CPython gets a chance to reuse the same memory 
address or not, whether you have a 32-bit or 64-bit Python compiler, whether 
any other objects are created in between each one, and many other factors.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] slashes in paths

2013-07-23 Thread Steven D'Aprano

On 23/07/13 04:33, Marc Tompkins wrote:

On Mon, Jul 22, 2013 at 11:30 AM, Jim Mooney wrote:


On 22 July 2013 11:26, Marc Tompkins  wrote:





If you haven't already read it, may I suggest Joel's intro to Unicode?
http://www.joelonsoftware.com/articles/Unicode.html



I had a bad feeling I'd end up learning Unicode ;')



It's not as painful as you might think!  Try it - you'll like it!
Actually, once you start getting used to working in Unicode by default,
having to deal with programs that are non-Unicode-aware feels extremely
irritating.



What he said!

Unicode brings order out of chaos. The old code page technology is horrible and 
needs to die. It was just barely acceptable back in ancient days when files 
were hardly ever transferred from machine to machine, and even then mostly 
transferred between machines using the same language. Even so, it didn't work 
very well -- ask Russians, who had three mutually incapable code pages.


The basics of Unicode are very simple:

- text strings contain characters;

- what is written to disk contains bytes;

- you need to convert characters to and from bytes, regardless of whether you 
are using ASCII or Unicode or something else;

- the conversion uses a mapping of character to byte(s), and visa versa, called 
an encoding;

- ASCII is an encoding too, e.g. byte 80 <=> "P";

- use the encode method to go from text to bytes, and decode to go the other 
way;

- if you don't know what encoding is used, you cannot tell what the bytes 
actually mean;

- although sometimes you can guess, with a variable level of success.



Remember those rules, and you are three quarters of the way to being an expert.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Marc Tompkins
On Tue, Jul 23, 2013 at 12:09 AM, Jim Mooney wrote:

> I've noticed that when I create a number of objects from a class, one
> after another, they're at different IDs, but the IDs all appear to be
> equidistant, so that they all appear to have the same size. But what does
> that size represent? is it bytes? ie - if I run this over and over I get
> different id numbers but they are always 40 apart. Or is that distance
> machine-specific as to units?:
>

>
> 41599624 - different results for each run but always 40 apart
> 41599664
> 41599704
> '''
>

When I saved your code as a file on my machine (Python 2.7 on Win8 64-bit)
and ran it from the command line, I got the same result as you - three IDs,
40 apart every time.  However, I initially pasted your code into
PyScripter, and when I ran it inside PyScripter the results were different:
if the first ID was x, then the second was x+160, and the third was x+200.
(160 is obviously divisible by 40... I have no idea what conclusion to draw
from that.)

I simplified the test-harness portion as follows:
kronkList = []
for kronknum in xrange(0,100):
kronkList.append(Kronk(kronknum))
print(kronkList[kronknum].getzar())
print(kronkList[kronknum].getself())

and now the ID is incremented by 40 each time regardless how I run the
script.

Each time I run it, the last digit stays the same throughout the run (as
you would expect, given that we're adding 40 each time), but the last
digits are NOT consistent _between_ runs.  It appears to always be an even
number, though.

As an experiment, I added a couple of extra methods and attributes to the
Kronk class, but it didn't change anything - IDs still incremented by 40
each time.  eryksun will no doubt chime in to tell us exactly how object
IDs are derived in cPython, but I'll go out on a limb and say that they
have nothing to do with the size of the object; also that one would be very
silly to make a program rely in any way on predicting the next ID, since
external factors may throw off the calculations (as when I invoked your
original script from inside PyScripter).  All that you can rely on is that
each unique object (i.e. doesn't pass an "is" comparison with any other
object) has a unique ID... and, for all I know, not even that.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Jim Mooney
On 23 July 2013 00:40, Steven D'Aprano  wrote:

>
> No no no, a thousand times no!!! IDs are just numeric IDs, that is all,
> like your social security number or driver's licence number. Don't think of
> them as having any meaning at all, except that they are unique during the
> lifetime of the object.
>

Okay, ID stands for a location fixed until the object disappears, but we
don't know where that location is. But what about object offsets from self?
Is the beginning of self.spam always the same distance from the beginning
of self.eggs? Or can I just forget the hard ground of assembler-metaphors
entirely as I float off into abstractville? I guess the fixed lengths I
kept getting on re-runs were coincidental but not to be relied on.

-- 
Jim
An excellent animation/graph of the accelerating disappearance of arctic
sea ice, which controls climate in the Northern hemisphere:
https://www.youtube.com/watch?v=YgiMBxaL19M
It is incontrovertible that Something is happening.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Marc Tompkins
On Tue, Jul 23, 2013 at 1:13 AM, Marc Tompkins wrote:


> As an experiment, I added a couple of extra methods and attributes to the
> Kronk class, but it didn't change anything - IDs still incremented by 40
> each time.  eryksun will no doubt chime in to tell us exactly how object
> IDs are derived in cPython, but I'll go out on a limb and say that they
> have nothing to do with the size of the object; also that one would be very
> silly to make a program rely in any way on predicting the next ID, since
> external factors may throw off the calculations (as when I invoked your
> original script from inside PyScripter).  All that you can rely on is that
> each unique object (i.e. doesn't pass an "is" comparison with any other
> object) has a unique ID... and, for all I know, not even that.
>

A couple of clarifications I wish I'd made before hitting Send:  I
shouldn't have said that IDs are "derived" or "calculated"; they're
"assigned", presumably on a first-come, first-served basis; when I said
"external factors may throw off the calculations" I meant "may make your
calculations non-congruent with reality".
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Marc Tompkins
On Tue, Jul 23, 2013 at 1:17 AM, Jim Mooney wrote:

> On 23 July 2013 00:40, Steven D'Aprano  wrote:
>
>>
>> No no no, a thousand times no!!! IDs are just numeric IDs, that is all,
>> like your social security number or driver's licence number. Don't think of
>> them as having any meaning at all, except that they are unique during the
>> lifetime of the object.
>>
>
> Okay, ID stands for a location fixed until the object disappears, but we
> don't know where that location is. But what about object offsets from self?
> Is the beginning of self.spam always the same distance from the beginning
> of self.eggs? Or can I just forget the hard ground of assembler-metaphors
> entirely as I float off into abstractville? I guess the fixed lengths I
> kept getting on re-runs were coincidental but not to be relied on.
>

As Steven said: they are NOT locations, they are IDs.  There is no distance
involved.  You CAN find the size of an object, and you can find its
location in memory (but you really shouldn't bother, or rely on it) but
neither of those things has any particular relation to the ID, except
accidentally.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] slashes in paths

2013-07-23 Thread Jim Mooney
On 23 July 2013 00:42, Steven D'Aprano  wrote:

My, that is simple. The Python docs should start with simple explanations
like that so people would keep on reading instead of throwing up their
hands in despair ;')

>
> - use the encode method to go from text to bytes, and decode to go the
> other way;
>

My favorite part. Real bytes, not imaginary IDs ;')


Jim
An excellent animation/graph of the accelerating disappearance of arctic
sea ice, which controls climate in the Northern hemisphere:
https://www.youtube.com/watch?v=YgiMBxaL19M
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Jim Mooney
On 23 July 2013 01:13, Marc Tompkins  wrote:

When I saved your code as a file on my machine (Python 2.7 on Win8 64-bit)
> and ran it from the command line, I got the same result as you - three IDs,
> 40 apart every time.  However, I initially pasted your code into
> PyScripter, and when I ran it inside PyScripter the results were different:
> if the first ID was x, then the second was x+160, and the third was x+200.
> (160 is obviously divisible by 40... I have no idea what conclusion to draw
> from that.)
>

I like PyScripter, but I suspect it injects a lot of behind-the-scenes
code. At times it does something odd or just chokes, so if something looks
funny, I run it from Wing 101, which nearly always gives the same result as
the command line and has yet to choke. And the command line, of course, is
the final arbiter once a program is complete. So far, Wing 101 has
fulfilled my expectations as a basic Python IDE, so it's the one I'll buy
if I fall into money.

PyCharm might be good but they don't have a free version and I'm not
learning a tryout I might have to ditch. Which means the folks at Wing are
smarter marketers by giving away the basic version ;')  I think that Joel
guy at .joelonsoftware.com mentioned something to that effect. An excellent
site to peruse when I'm feeling brain-dead and need a break.

Speaking of brain dead, I was taking a break from Python by looking at a
video on finite state machines and the very first example was tennis
scoring. I think the $#@! insane tennis scoring was harder to understand
than the subject.

Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Jordan




Speaking of brain dead, I was taking a break from Python by looking at 
a video on finite state machines and the very first example was tennis 
scoring. I think the $#@! insane tennis scoring was harder to 
understand than the subject.
That got me laughing pretty good, since I too was recently trying to 
learn Finite State Machines.  I play tennis occasionally and still 
forget how to score properly!


Jim



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Dave Angel

On 07/23/2013 02:10 AM, Jim Mooney wrote:

On 22 July 2013 21:00, Steven D'Aprano  wrote:



(By the way, you're very naughty. The code you show *cannot possibly
generate the error you claim it generates*. Bad Jim, no biscuit!)



I know. I need a personal github.


git is free, and is usually installed on individual machines.  It's also 
easy to set up and use for a single user.


http://githowto.com/setup

Where git gets complex is when multiple users are making simultaneous 
changes.  And even there, it's about as complicated as it needs to be, 
and very powerful.


Once you've installed git, you don't even need internet access.  Even if 
you're in a multiplayer project, you only need it for some operations, 
not for the run of the mill snapshots you'd like to do.



When I get frustrated I try so many
things in quick succession I lose track. The worst is when I got something
working, but was moving so fast, I forgot how ;')



One git feature I haven't used in a long time is the ability to test 
MANY versions against a particular test.  If I recall correctly, the 
test should return a nonzero return code (eg. sys.exit(5)) for error. 
Anyway, you start up the git script, telling it the test name, and it'll 
repeatedly get versions till it finds the one you're looking for.


--
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Steven D'Aprano

On 23/07/13 18:19, Marc Tompkins wrote:


A couple of clarifications I wish I'd made before hitting Send:  I
shouldn't have said that IDs are "derived" or "calculated"; they're
"assigned", presumably on a first-come, first-served basis;


Actually, in CPython they are derived, from the memory location, which annoys 
me no end :-)

But in Jython and IronPython they are assigned, when and as requested.

Some day, I'll invent my own version of Python, and make object IDs be 
consecutive prime numbers. That'll teach people to rely on them.

:-)


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Steven D'Aprano

On 24/07/13 00:14, Dave Angel wrote:

On 07/23/2013 02:10 AM, Jim Mooney wrote:

On 22 July 2013 21:00, Steven D'Aprano  wrote:



(By the way, you're very naughty. The code you show *cannot possibly
generate the error you claim it generates*. Bad Jim, no biscuit!)



I know. I need a personal github.


git is free, and is usually installed on individual machines.  It's also easy 
to set up and use for a single user.


I prefer Mercurial (also known as hg). The Python core developers use it for 
compiler development, and in my opinion, hg is easier to use than git. 
(Although, in fairness, they're both pretty easy.) hg is cleaner than git, 
being written in Python, while git is an unholy mess of C, Perl and bash that 
will suck your brain out if you try to understand it, unless you are Linus 
Torvalds. And there are some awesome hg tutorials out there:

http://hginit.com/
http://mercurial.selenic.com/wiki/Tutorial

(I trust that everyone remembers enough high school chemistry to understand why 
Mercurial is called hg? Hg is the chemical symbol for Mercury.)


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Steven D'Aprano

On 24/07/13 00:21, Oscar Benjamin wrote:


The reason for the patterns that you observe are related to CPython's
memory pool allocator. You can read the long source comment describing
this here:
http://hg.python.org/cpython/file/a5681f50bae2/Objects/obmalloc.c#l367


[...]


Nice analysis! Thanks Oscar!


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Steven D'Aprano

On 23/07/13 18:17, Jim Mooney wrote:

On 23 July 2013 00:40, Steven D'Aprano  wrote:



No no no, a thousand times no!!! IDs are just numeric IDs, that is all,
like your social security number or driver's licence number. Don't think of
them as having any meaning at all, except that they are unique during the
lifetime of the object.



Okay, ID stands for a location fixed until the object disappears, but we
don't know where that location is.


No, it does not stand for a location. It is an identification number, that is 
all.

In CPython, every value (lists, strings, integers, custom classes) are objects 
which exist in one location until destroyed. In Jython and IronPython, values 
are objects which can move from location to location, in order to free up 
memory for new objects. In PyPy, not only can objects move, but they can also 
be invisibly turned into low-level data structures for efficient processing. So 
in CPython, Jython and IronPython, an object's identity is fixed. In PyPy, 
object identity is an illusion, and according to the PyPy developers, keeping 
that illusion working requires a lot of effort.


But what about object offsets from self?


That's always zero, since self is the object :-)

You can read up about the implementation of CPython here:

http://docs.python.org/2/c-api/

but this describes only the C interface, not the concrete implementation. For 
that you pretty much have to read the source code. The C source code.



Is the beginning of self.spam always the same distance from the beginning
of self.eggs? Or can I just forget the hard ground of assembler-metaphors
entirely as I float off into abstractville? I guess the fixed lengths I
kept getting on re-runs were coincidental but not to be relied on.


Understanding a little of the concrete implementation details will help you 
understand some of Python's design, and its limitations. But apart from that, 
it's not necessary, and sometimes it is actually counter-productive. Thinking 
in terms of low-level data can lead you wrong. For instance, when working in 
low-level languages, it is normal to write code to minimize moving data from 
place to place. For example, when sorting in C or assembly, comparing two 
values is cheap, but swapping them is expensive. In Python it is the opposite: 
swapping two values in a list just requires swapping two pointers, which is 
cheap, but the comparison is quite expensive and could call arbitrary user code.

In CPython, objects are implemented in C, and are a block of memory that 
contains various fields, and potentially pointers to other objects. The nature 
of those fields will depend on which type of object they are.

In Jython, objects are implemented in Java, and in IronPython they are 
implemented in C#, but otherwise are similar. But the layout of the fields will 
be different, and the fields themselves, except perhaps by accident.

In PyPy, objects are implemented in RPython, a restricted and simplified 
version of Python, which is then automatically translated by the optimizing 
compiler into some low-level data structure behind the scenes.

Since Python is defined by its behaviour, not any sort of concrete implementation, in 
principle one could invent a "Python Engine", like Babbage's Difference Engine, 
only thousands of times more complex, entirely out of clockwork. Or by water flowing 
through pipes, or reproducing DNA in a test tube, or some exotic quantum field. Or simply 
simulate a Python interpreter in your head, perhaps aided by pencil and paper.


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] close, but no cigar

2013-07-23 Thread Steven D'Aprano

On 23/07/13 04:27, Jim Mooney wrote:

Okay, I'm getting there, but this should be translating A umlaut to an old
DOS box character, according to my ASCII table,



I understand what you mean, but I should point out that what you say is 
*literally impossible*, since neither Ä nor any box-drawing characters are part 
of ASCII. What you are saying is figuratively equivalent to this:

...should be translating Москва to モスクワ according to my Latin to French 
dictionary...

Even if the ancient Romans knew of the city of Moscow, they didn't write it in 
Cyrillic and you certainly can't get Japanese characters by translating it to 
French.

Remember that ASCII only has 128 characters, and *everything else* is non-ASCII, whether they are 
line-drawing characters, European accented letters, East Asian characters, emoticons, or ancient 
Egyptian. People who talk about "extended ASCII" are confused, and all you need to do to 
show up their confusion is to ask "which extended ASCII do you mean?" There are dozens.

For example, ordinal value 0xC4 (hex, = 196 in decimal) has the following meaning 
depending on the version of "extended ASCII" you use:

Ä LATIN CAPITAL LETTER A WITH DIAERESIS
 HEBREW POINT HIRIQ
Δ GREEK CAPITAL LETTER DELTA
ؤ ARABIC LETTER WAW WITH HAMZA ABOVE
─ BOX DRAWINGS LIGHT HORIZONTAL
ƒ LATIN SMALL LETTER F WITH HOOK


using encodings Latin1, CP1255, ISO-8859-7, ISO-8859-6, IBM866, and MacRoman, 
in that order. And there are many others.

So the question is, if you have a file name with byte 196 in it, which 
character is intended? In isolation, you cannot possibly tell. As an English 
speaker, I've used at least four of the above six, although only three in file 
names. With single-byte encodings, limited to a mere 256 characters (128 of 
which are already locked down to the ASCII charset[1]), you can't have all of 
the above except by using Unicode[2].

The old "code pages" technology is sheer chaos, and sadly we'll be living with 
it for years to come. But eventually, maybe in another 30 years or so, everyone will use 
Unicode all the time, except for specialist and legacy needs, and gradually we'll get 
past this nonsense of dozens of encodings and moji-bake and other crap.





[1] Not all encodings are ASCII-compatible, but most of them are.

[2] Or something like it. In Japan, there is a proprietary charset called TRON 
which includes even more characters than Unicode. Both TRON and Unicode aim to 
include every human character which has ever been used, but they disagree as to 
what counts as distinct characters. In a nutshell, there are some tens of 
thousands or so characters which are written the same way in Chinese, Japanese 
and Korean, but used differently. Unicode's policy is that you can tell from 
context which is meant, and gives them a single code-point each, while TRON 
gives them three code-points. This is not quite as silly as saying that an 
English E, a German E and a French E should be considered three distinct 
characters, but (in my opinion) not far off it.


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Dave Angel

On 07/23/2013 10:28 AM, Steven D'Aprano wrote:

On 24/07/13 00:14, Dave Angel wrote:

On 07/23/2013 02:10 AM, Jim Mooney wrote:

On 22 July 2013 21:00, Steven D'Aprano  wrote:



(By the way, you're very naughty. The code you show *cannot possibly
generate the error you claim it generates*. Bad Jim, no biscuit!)



I know. I need a personal github.


git is free, and is usually installed on individual machines.  It's
also easy to set up and use for a single user.


I prefer Mercurial (also known as hg). The Python core developers use it
for compiler development, and in my opinion, hg is easier to use than
git. (Although, in fairness, they're both pretty easy.) hg is cleaner
than git, being written in Python, while git is an unholy mess of C,
Perl and bash that will suck your brain out if you try to understand it,
unless you are Linus Torvalds. And there are some awesome hg tutorials
out there:

http://hginit.com/
http://mercurial.selenic.com/wiki/Tutorial

(I trust that everyone remembers enough high school chemistry to
understand why Mercurial is called hg? Hg is the chemical symbol for
Mercury.)





My comment was in response to github.  I've never investigated 
Mercurial.  In various companies over the years, I've used probably a 
dozen different source control systems, and git was the latest, and to 
my thinking, best of them.


I also installed git on this machine a couple of days ago, so the 
easy-start link was handy.



--
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] close, but no cigar

2013-07-23 Thread Marc Tompkins
On Tue, Jul 23, 2013 at 7:46 AM, Steven D'Aprano wrote:

> This is not quite as silly as saying that an English E, a German E and a
> French E should be considered three distinct characters, but (in my
> opinion) not far off it.
>

I half-agree, half-disagree.  It's true that the letter "E" is used
more-or-less the same in English, French, and German; after all, they all
use what's called the "Latin" alphabet, albeit with local variations.  On
the other hand, the Cyrillic alphabet contains several letters that are
visually identical to their Latin equivalents, but used quite differently -
so it's quite appropriate that they're considered different letters, and
even a different alphabet.
I don't know enough about the similarities and differences between various
East Asian languages to know whether, say, Chinese and Korean are more like
English and German or more like English and Russian - but that, rather than
the visual similarity, would be my criterion for deciding.

Spot the differences:

A  Аa  а
B  Вb  в
C  Сc  с
E  Еe  е
Ë  Ёë  ё
K  Кk  к
M  М   m м
   n  п
O  Оo  о
P  Рp  р
T  Т t   т
  u  и
X  Х x  х
Y  Уy  у

A few notes:
-  this won't look right unless your email client is Unicode-capable
-  no, I'm not saying that these letters are equivalent - some (T and Т, K
and К) basically are, others (E and Е, n and п) definitely are not - I'm
just saying that they are visually similar if not identical
-  just HOW similar they are depends on which typeface you use.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Alan Gauld

On 23/07/13 16:08, Dave Angel wrote:



git is free, and is usually installed on individual machines.  It's
also easy to set up and use for a single user.


I prefer Mercurial (also known as hg).


And I've used SVN in recent years and found it... OK.

But my question is: Why is there such a rash of source code control 
systems just now?


I used SCCS and RCS and then CVS for years and they seemed
to work just fine (especially CVS for larger projects). So what is
the itch that everyone is trying to scratch with these new systems? 
Personally I don't find them significantly better or even different to 
the previous generation. (Unlike the commercial products I've used like 
ClearCase(*) and Continuous which are vastly superior but vastly more 
expensive!)


So what's the big deal with version control?

(*)On Unix only, on Windows ClearCase is not significantly better
than any other VCS

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A list of 100+ projects to complete to master Python.

2013-07-23 Thread David Hutto
The offsite backups, are just a safety measure for your programs, this can
include things such as sourceforge so you don't lose your work to a glitch,
which can happen without a moments notice.

You want to master python, then reinvemnt the wheel sometimes. Most
everything has beeen done. It's data, and data manipulation, so you can do
it your way, or look at the code that original used, and do it your way.
Remember the 'zen' of python, to reduce complex lower level macros into
higher level reductions of these more complex codes. Just do it your own
way.

And as far as the API's, that is to utilize other programs that allow you
to use functions, and python programming within other software. Like a cell
phone will have a Python API so you can utilize python on individual
devices, and other software that will translate, or have a python library
in which you can use python code anywhere, as the language grows in it's
utilization in several areas.



On Wed, Jul 17, 2013 at 1:26 AM, Karan Goel  wrote:

> I'm not entirely sure if your reply was directed towards my message.
>
> - Karan Goel
> Goel.im  | 
> Resume
>  | Github 
>
>
> On Wed, Jul 17, 2013 at 5:09 AM, David Hutto wrote:
>
>> First thing you should learn is offsite backups, I've lost several
>> projects in the works because of a hd mishap. Secondarily, I would
>> recommend using existing primarily used python projects to 'reinvent the
>> wheel' so to speak. Thirdly, make sure the code is properly documented, and
>> serves a purpose. And lastly, utilize other programs with python api's,
>> such as blender, which can make your apps pop, or diversify into game
>> development kits.
>>
>>
>> On Tue, Jul 16, 2013 at 1:09 PM, Karan Goel  wrote:
>>
>>> Hey guys and gals
>>>
>>> Just a plug here. My repo: https://github.com/thekarangoel/Projects
>>> was one of the trending repos on Gh this week and I thought folks
>>> on this list might be interested in knowing about it.
>>>
>>> In a nutshell, I'm trying to complete over a 100 practical language-
>>> agnostic projects in Python only. I haven't read the project details yet,
>>> and I'm not filtering things out.
>>>
>>> If you would like to do the same, join me. Fork or star the repo,
>>> and start coding (in any language, really).
>>>
>>> https://github.com/thekarangoel/Projects
>>>
>>> Let me know if you have any questions or suggestions.
>>>
>>> - Karan Goel
>>> Goel.im  | 
>>> Resume
>>>  | Github 
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>>
>> --
>> Best Regards,
>> David Hutto
>> *CEO:* *http://www.hitwebdevelopment.com*
>>
>
>


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] suggestions for splitting file based on date

2013-07-23 Thread David Hutto
You could also begin a little stats(I think steven D'aprano did pystats),
which would show rhythms within those particular frequency windows, using y
as a basis for your model


On Sat, Jul 20, 2013 at 1:10 AM, David Hutto  wrote:

> Why not use the actual month? With a simple x/y canvas in Tkinter you
> could plot by the months with polygon coordinates as your data
> visualization, or in 30 day /etc windows, just the price(y) being a
> derivative  of x(the frequency of changes), and create simple line segments
> with polygon coordinates, and refine them to
> hourly/daily/weekly/monthly/yearly, or in 30/60/90 day increments with a
> little url scraping.
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] suggestions for splitting file based on date

2013-07-23 Thread David Hutto
Why not use the actual month? With a simple x/y canvas in Tkinter you could
plot by the months with polygon coordinates as your data visualization, or
in 30 day /etc windows, just the price(y) being a derivative  of x(the
frequency of changes), and create simple line segments with polygon
coordinates, and refine them to hourly/daily/weekly/monthly/yearly, or in
30/60/90 day increments with a little url scraping.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 3 Dimensional Dictionaries

2013-07-23 Thread David Hutto
You could find several url's to scrape the data from, and I believe it was
mentioned you could use a list of dicts, but it seems that you might want
to sub tier your dicts, It's been a while since I've pythoned so this a
little longer that usual, but this may help if you pull in the
countries/continents/states/provinces/zipcodes, however you may stil want
to give a DB a try, which you can create on your own out of
dictionaries/with list tuples, and subdicts.

\but if you always wnat dynamic data, rescraping several url's at a
personally optimized frequency into your db could help

import random
continents = ['china','u.s']

def world_stats():
world = {}

for continent in continents:
world[continent] = {'periodic_table_resources': {} }
print(continent)


for periodic_elements in range(0,119):
rand = random.randint(0,101)
world[continent]['periodic_table_resources'] =
'periodic_table_element %i=' % (periodic_elements)
print(world[continent]['periodic_table_resources'], rand, '%')



world_stats()

This doesn't contain the url scraper yet.


On Mon, Jul 22, 2013 at 10:44 PM, Sunil Tech wrote:

>
>
> On Tuesday, July 23, 2013, Sunil Tech  wrote:
> > THANK YOU ALL for your time.
> >
> > The first format which I pasted was from the DB
> >
> > The second format(exactly the same), is to be sent to the view.
> >
> > If the logic can be fitted in One or two methods it'll help me to easily
> understand & to apply.
> >
> > so I request you to help...
> >
> >
> > On Sunday, July 21, 2013, Alan Gauld  wrote:
> >> On 20/07/13 11:17, Sunil Tech wrote:
> >>>
> >>> Hi Everyone,
> >>>
> >>> I have a list of dictionaries like
> >>>
> >>> world =
> >>>
> [{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Kerala',
> >>> 'state_pin':51},
> >>
> >>>
> >>> i am trying to to make it in this format
> >>>
> >>> world = [{'continent':'Asia', 'ocean':'Pacific',
> >>> 'countries':[{'country':'India',
> >>> 'states':[{'state':'Kerala', 'state_pin':51},
> >>> {'state':'Karnataka', 'state_pin':52}]
> >>> }]
> >>> },
> >>
> >>> Please help me in this regard.
> >>
> >> In what regard? Where do you need the help?
> >> You seem to know the data format you want?
> >>
> >> The only thing I'd suggest is to consider using classes if you are
> familiar with them.
> >>
> >> world => list of continents
> >> continent => class containing countries
> >> country => class containing states
> >> state => class containing data
> >>
> >> It then becomes easier to build helper methods to extract/manipulate
> the data you are interested in.
> >>
> >> Alternatively, if you have a large amount of data a database may be
> another option. Swap table for class above and use SQL to manage the data.
> >>
> >> But other than those suggestions I don't know what kind of
> >> help you want?
> >>
> >> --
> >> Alan G
> >> Author of the Learn to Program web site
> >> http://www.alan-g.me.uk/
> >>
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> To unsubscribe or change subscription options:
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question

2013-07-23 Thread Amandeep Behl
def Move(label):
  label = "Anything"

a_list = [1,2,3]
Move(a_list)

I don't see any error when executing above but  when i manually assign
[1,2,3] = "Anything" i get error
 Why?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hi

2013-07-23 Thread Vick
Hello,

 

Thanks for taking the time to reply!

 

However, I had already solved the problem a few days ago on my own.

 

The DOPRI 8(7)13 is the Dormand Prince 8th order with 13 stages method for
solving  
ordinary differential equations. It is a member of the Runge-Kutta family of
ODE solvers. I have been able to reproduce it in Python with a
multi-variable capability. On a particular test equation the error of the
RK4 is about 1e-4 whereas the DOPRI 8(7)13 is about 1e-13.

 

I have then used the multi-variable DOPRI to compute for the n-body problem
using 1st order ODEs which requires you to have 4 equations for 1 planet. I
have already made a 10-body problem through an n-body solver in python and
using DOPRI as my integrator.

 

It works fine.

 

Thanks again for your time and consideration.

 

Regards

Vick

 

 

-Original Message-
From: Oscar Benjamin [mailto:oscar.j.benja...@gmail.com] 
Sent: Monday, 22 July, 2013 15:59
To: Vick
Cc: Tutor@python.org
Subject: Re: [Tutor] hi

 

On 12 July 2013 11:08, Vick < 
vick1...@orange.mu> wrote:

> Hi,

 

Hi Vick,

 

Sorry for the delayed response I didn't see this email until a while after
you sent it.

 

> I have written a code to perform a numerical solution to 1st order 

> Ordinary Differential Equations (ODEs). I have written codes for the 

> famous Runge Kutta 4th order and the DOPRI 8(7)13. However the codes 

> are for 1 variable only; viz. the "y" variable.

 

It would be good to show us the code for this in your email (not in an
attachment). Also the code should be complete: the code uses a function
rungkdp8 which is not shown. Where did that come from? Until you know what
you're doing you should test your integrator on a simpler set of equations.
Also when posting to a mailing list you should simplify the problem as much
as possible which would mean using simpler ODEs. In short read this:

  http://sscce.org/

 

The code attached is incorrect as it applies each stage of the Runge-Kutta
method to all time-steps sequentially before moving on to the next stage. It
should apply each stage for one time step and then use the output of that
for the next time-step. In other words you need to change the order of the
loops.

 

Here is an example of how to implement an Euler stepper that should
hopefully get you started on the right track. I've deliberately avoided
using numpy in this example even though it makes most of this easier. I did
this to focus on the basics of Python which you should learn first.

 

# integrator.py

 

nan = float('nan')

 

# indices for the two variables in the system POS = 0 VEL = 1 VARS = ['pos',
'vel']

 

# system has one parameter OMEGA

OMEGA = 10  # Frequency in Hz is OMEGA / 2pi

 

# function for the derivative of the system def shm(t, x, dxdt):

'''Equation of motion for a mass in a spring with freq OMEGA'''

dxdt[POS] = x[VEL] # Python uses square brackets for indexing

dxdt[VEL] = - OMEGA**2 * x[POS]

 

# Initial conditions for the problem

x0 = [nan] * 2

x0[POS] = 1

x0[VEL] = 0

 

# This is the function that you should replace with e.g. rk4 or dopri8 def
euler(t1, x1, t2):

'''Take 1 Euler step from x1 at t1 to x2 at t2'''

# Create empty lists for answer

x2 = [nan] * len(x1)

dxdt = [nan] * len(x1)

# Call derivative function to fill in dxdt

shm(t1, x1, dxdt)

# Compute x2 and return

dt = t2 - t1

for n in range(len(x1)):

x2[n] = x1[n] + dt * dxdt[n]

return x2

 

def solve(ts, x0):

'''Compute states corresponding to the times in ts

 

x0 is the state at ts[0] (the initial condition).

'''

# Create an empty list of lists for the solution

Xt = [x0[:]]  # The initial conditions

# Loop through timesteps computing the next value

for n in range(len(ts) - 1):

Xt.append(euler(ts[n], Xt[n], ts[n+1]))

return Xt

 

def print_line(*items):

print(', '.join(str(i) for i in items))

 

def print_solution(ts, Xt, vars):

print_line('t', *vars)

for t, x in zip(times, Xt):

print_line(t, *x)

 

# Numerical parameters for the solution

DT = 0.001

t0 = 0

T  = 1

times = [t0]

while times[-1] < T:

times.append(times[-1] + DT)

 

# Solve and print

Xt = solve(times, x0)

print_solution(times, Xt, VARS)

 

 

> I have written another code in Excel VBA for DOPRI 8 for a 

> multi-variable capability. However I have not been able to reproduce 

> it in Python. I'm having trouble in making arrays or lists, I don't 

> know which is supposed to work.

> 

> I have attached my Excel VBA code for a multi-variable numerical 

> integrator in PDF format. This does work in Excel. I have also attached my
python code.

 

I'm not familiar with Excel VBA but I think that this code suffers from the
same problem that the loop over stages takes place outside the loop over
ti

Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Jim Mooney
On 23 July 2013 07:21, Oscar Benjamin  wrote:

>
>
> You can check the size in bytes of an object with sys.getsizeof e.g.:
>
> >>> import sys
> >>> sys.getsizeof(lardKronk)
> 36
>

And yet I still get 36 with this:

bigKronk = Kronk('supercalifracilisticexpalidocious, even though the sound
of it is really quite atrocious')
sys.getsizeof(bigKronk)
36

So I guess the object is only pointing to its contents.  Which I assume
means an object is just a bunch of names bound to pointers.

Jim
An excellent animation/graph of the accelerating disappearance of arctic
sea ice, which controls
climate stability in the Northern hemisphere:
https://www.youtube.com/watch?v=YgiMBxaL19M
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] close, but no cigar

2013-07-23 Thread Jim Mooney
On 23 July 2013 07:46, Steven D'Aprano  wrote:People
who talk about

"extended ASCII" are confused, and all you need to do to show up their
confusion is to ask "which extended ASCII do you mean?" There are dozens.

  I think I was too impressed by all those wonderful old ASCII-art pics on
bulletin boards. I bet Msoft didnt' predict That when they invented their
box-drawing chars - more Unintended Consquences, but benign ones for a
change.  Some of them were truly amazing. I'll have to go do a webhunt for
them.

Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Jim Mooney
On 23 July 2013 07:19, Steven D'Aprano  wrote:


> Some day, I'll invent my own version of Python, and make object IDs be
> consecutive prime numbers. That'll teach people to rely on them.
>
---

Why "consecutive?" That's still way too predictable (Yes, the obvious flaw
already occurred to me ;')

Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Jim Mooney
On 23 July 2013 07:28, Steven D'Aprano  wrote:

>
> (I trust that everyone remembers enough high school chemistry to
> understand why Mercurial is called hg? Hg is the chemical symbol for
> Mercury.)
>

And I recall my high school chemistry teacher claiming the noble gases
could never combine, until someone just decided to cook  up some Xenon
Tetraflouride. Always fun when you get to contradict your teacher in class,
and you're right - wel it was then. I'm a tad more mature, now - sometimes
;')

There are always surprises.

Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] object size in python is in what units?

2013-07-23 Thread Alan Gauld

On 23/07/13 19:27, Jim Mooney wrote:


And yet I still get 36 with this:

bigKronk = Kronk('supercalifracilisticexpalidocious, even though the
sound of it is really quite atrocious')
sys.getsizeof(bigKronk)
36

So I guess the object is only pointing to its contents.


Python namespaces are effectively dictionaries binding a name
with an object reference.  The object in turn is like a dictionary 
referring to the values. So I guess you are seeing the object

container size.


means an object is just a bunch of names bound to pointers.


Pretty much everything in Python looks like a dictionary
so I'd guess you are correct.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Alan Gauld

On 23/07/13 18:41, wolfrage8...@gmail.com wrote:

Although I can not say for sure.  It appears to me, they are trying to
do a better job at merging from distributed branches


Thanks for the memory jog. Yes i remember reading an interview with 
linus when he referred to the difficulty of using CVS on a

distributed build and that was a prime motivator for git.

Now what about the others? Are they also primarily aimed at
distributed builds?

Renaming files and folders should not be a big problem for
any VCS, if you freeze/recreate the tree the folder names
should be whatever they were at freeze. (The only issue is
if you want to pull up version -N of a file and its
history stops at version -(N+3) and you then need to
pull up version (-3) of the old file and don't know its name!
- bad commenting and history documentation, but not unknown.
But the tool can do it, its only the management that's
faulty! :-)

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] close, but no cigar

2013-07-23 Thread Steven D'Aprano

On 24/07/13 03:01, Marc Tompkins wrote:

On Tue, Jul 23, 2013 at 7:46 AM, Steven D'Aprano wrote:


This is not quite as silly as saying that an English E, a German E and a
French E should be considered three distinct characters, but (in my
opinion) not far off it.



I half-agree, half-disagree.  It's true that the letter "E" is used
more-or-less the same in English, French, and German; after all, they all
use what's called the "Latin" alphabet, albeit with local variations.  On
the other hand, the Cyrillic alphabet contains several letters that are
visually identical to their Latin equivalents, but used quite differently -
so it's quite appropriate that they're considered different letters, and
even a different alphabet.


Correct. Even if they were the same, if legacy encoding systems treated them differently, so would 
Unicode. For example, \N{DIGIT FOUR} and \N{FULLWIDTH DIGIT FOUR} have distinct code-points, even 
though they are exactly the same character, since some legacy East-Asian encodings had separate 
characters for "full-width" and "half-width" forms.

But I confess I have misled you. I wrote about the CJK controversy from memory, 
and I'm afraid I got it completely backwards: the problem is that the glyphs 
(images of the characters) are different, but not the meaning. Mea culpa.

For example, in English, we can draw the dollar sign $ in two distinct ways, with one 
vertical line, or two. Unicode treats them as the same character (as do English 
speakers). "Han Unification" refers to Unicode's choice to do the same for many 
Han (Chinese, Korean, Japanese) ideographs with different appearance but the same 
meaning. For various reasons, some technical, some social, this choice proved to be 
unpopular, particularly in Japan. This issue is nothing new -- Unicode supports about 
71,000 distinct East Asian ideographs, which is *far* more than the old legacy encodings 
were capable of representing, so if there is a Han character that you would like to write 
which Unicode doesn't support, chances are that neither does any other encoding system.

More here:

https://en.wikipedia.org/wiki/Han_unification
http://www.unicode.org/faq/han_cjk.html
http://slashdot.org/story/01/06/06/0132203/why-unicode-will-work-on-the-internet



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2d rotation gives unexpected results.

2013-07-23 Thread Dave Angel

On 07/23/2013 08:27 AM, enmce wrote:

Hello!
This is my first post, nice to meet you all!
I`m biology student from Russia, trying to learn python to perform some simple 
simulations.


Hello, and welcome.

However, please don't post identical messages on tutor and python-list. 
 The response you got there from Peter Otten was right on.


Here`s my first problem.
I`m trying to perform some simple 2d vector rotations in pygame, in order to 
learn the basics of linear algebra and 2d transformations. So far i understand 
matrix multiplication pretty well, and probably all my math is right. 
Eventually i`m planning to write Poly class, and use it to rotate and translate 
some simple shapes. But when i try and write it in the program, i get very 
weird results, like all points of rectangle with coordinates 
[0,0],[0,100],[100,0],[100,100] start to go spiral and eventually shrink to the 
center instead of rotating right. Although even Excel calculations with this 
formulas give me right result.
What is wrong with my code?

[code]import pygame
import math as m

black = ( 0, 0, 0)
white = ( 255, 255, 255)
green = ( 0, 255, 0)
red = ( 255, 0, 0)

class Poly():
 pos = [100,100] #x and y coordinates of a point
 rot = m.radians(1) #rotation in degrees
 def draw(self): #draw point
 pygame.draw.circle(screen,white,self.pos,10,0)
 def rotate(self): # rotation method
 sin = m.sin(self.rot) #calculationg sin and cos
 cos = m.cos(self.rot)
 x_rot = int(self.pos[0]*cos-self.pos[1]*sin) #mulpitplicating vector 
to rotation matrix
 y_rot = int(self.pos[0]*sin+self.pos[1]*cos)



By calling int() on those two lines, you have just drastically changed 
the point's location.  That won't be visible right away, but when you 
use that value repeatedly, the error will add up pretty quickly.


In fact, just repeatedly calculating those values will eventually 
produce some noticeable errors.  Those errors can be eliminated as well, 
but it'll be a bit harder.






--
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Dave Angel

On 07/23/2013 03:20 PM, Alan Gauld wrote:

On 23/07/13 18:41, wolfrage8...@gmail.com wrote:

Although I can not say for sure.  It appears to me, they are trying to
do a better job at merging from distributed branches


Thanks for the memory jog. Yes i remember reading an interview with
linus when he referred to the difficulty of using CVS on a
distributed build and that was a prime motivator for git.

Now what about the others? Are they also primarily aimed at
distributed builds?


The three distributed version control systems I know of are:
   git, mercurial, and bazaar



--
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unichr not working as expected

2013-07-23 Thread Marc Tompkins
On Tue, Jul 23, 2013 at 12:31 PM, Dave Angel  wrote:

> The three distributed version control systems I know of are:
>git, mercurial, and bazaar
>

Not to overplay my Joel Spolsky fanboiism, but are you aware of Kiln from
Fog Creek?  It started out as an enterprise-friendly wrapper around
Mercurial (which is still Joel's favorite, apparently), but they decided to
make it agnostic: it now round-trips seamlessly between git and Mercurial,
with users of either not needing to know or care what other users prefer.

Of course, I haven't actually used it myself, so I only have the
developers' word to go by that it's the greatest thing since sliced bread -
but I thought I'd mention it.
http://www.joelonsoftware.com/items/2013/03/11.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Off Topic re: unichr not working as expected

2013-07-23 Thread Steven D'Aprano

On 24/07/13 04:53, Jim Mooney wrote:

On 23 July 2013 07:28, Steven D'Aprano  wrote:



(I trust that everyone remembers enough high school chemistry to
understand why Mercurial is called hg? Hg is the chemical symbol for
Mercury.)



And I recall my high school chemistry teacher claiming the noble gases
could never combine, until someone just decided to cook  up some Xenon
Tetraflouride. Always fun when you get to contradict your teacher in class,
and you're right - wel it was then. I'm a tad more mature, now - sometimes
;')



Completely off-topic, you may get a kick out of "Things I Won't Work With", 
where a professional chemist periodically writes about chemical compounds that he won't 
work with for various reasons:


- chemicals that set fire to sand, bricks, and asbestos;

- chemicals that stink so unbearably that fogging the air with nitric oxide 
actually *improves* the air quality;

- chemicals that detonate at -300°F;

- chemicals so explosive that mixing them with TNT makes them more stable;

- solutions that become more dangerous rather than less when you put them in 
the freezer;

- chemicals more reactive than elemental fluorine -- some of which are made 
*from* elemental fluorine;

- and chemicals which have short-term acute toxic effects, long-term chronic 
toxic effects if you survive the acute ones, and are carcinogenic if you 
survive the chronic toxicity.


http://pipeline.corante.com/archives/things_i_wont_work_with/



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Off Topic re: unichr not working as expected

2013-07-23 Thread Asokan Pichai
On Wed, Jul 24, 2013 at 1:50 AM, Steven D'Aprano wrote:

> On 24/07/13 04:53, Jim Mooney wrote:
>
>> On 23 July 2013 07:28, Steven D'Aprano  wrote:
>>
>>
>>> (I trust that everyone remembers enough high school chemistry to
>>> understand why Mercurial is called hg? Hg is the chemical symbol for
>>> Mercury.)
>>>
>>>
>> And I recall my high school chemistry teacher claiming the noble gases
>> could never combine, until someone just decided to cook  up some Xenon
>> Tetraflouride. Always fun when you get to contradict your teacher in
>> class,
>> and you're right - wel it was then. I'm a tad more mature, now - sometimes
>> ;')
>>
>
Way offtopic: It is Xenon Hexa Flouride IIRC. LOve that book 107 stories
about CHemistry

Asokan Pichai

"Expecting the world to treat you fairly because you are a good person is a
little like expecting the bull to not attack you because you are a
vegetarian"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite3 woes opening Moz, FFox sqlite db with only the inevitable 'DatabaseError: file is encrypted or is not a database' occurring...

2013-07-23 Thread Paul Smith
title = three days lost and counting...

Thanks in advance all:

Ok- I want to work with data in FFox, specifically a sqlite db found here..

'C:\Users\Hive2\AppData\Roaming\Mozilla\Firefox\Profiles\zabt0uq4.default\places.sqlite'

...more specifically my FFox history found in a table 'moz_places'.

Running Py 2.7.5 on a windows 7-64 machine and after days of
*consulting -*google; various-boards ;stackoverflow;
py.org; sqlite.org; mingw32?(prereq. for sqlite v. 2.6.3?); sphynx?(another
prereq. for I forget); and *addressing* - possible version differences
between sqlite3 and FFoxdb; file path confirmation; db creation - query
using sqlite3(successful); etc. etc.

We end up here...

import sqlite3 as lite
import sys
import os

print ("sqlite version info1:",lite.version)##clunky version confirm
print ("sqlite version info2:",lite.sqlite_version,"\n")##clunk's cousin

mypath =
os.path.realpath("C:\\Users\\Hive2\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\zabt0uq4.default\\places.sqlite")
mydb = (mypath)## I'm trying to confirm the path to the friggin' thing
print ("This is my db path""\n"+(mydb))
con = None
con = lite.connect(mydb)
with con:
cur = con.cursor()
cur.execute("SELECT * FROM 'moz_places'")## it is a table in places.sqlite
seems apropos
print (con.fetchall()) ## print it all?
con.close()

Which produces...

Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
on win32
Type "copyright", "credits" or "license()" for more information.
>>>  RESTART

>>>
('sqlite version info1:', '2.6.0')
('sqlite version info2:', '3.6.21', '\n')
This is my db path
C:\Users\Hive2\AppData\Roaming\Mozilla\Firefox\Profiles\zabt0uq4.default\places.sqlite

Traceback (most recent call last):
  File "E:\pyurlseek\zedpathconfirm.py", line 15, in 
cur.execute("SELECT * FROM 'moz_places'")
DatabaseError: file is encrypted or is not a database

I just want to print out the table (or anything from the FFox db just to
prove it is being opened/accessed?!)

I am sure it is a simple error but being a real newb that I am I cannot
escape the dreaded 'DatabaseError: file is encrypted or is not a database',
time and time again.

Help please

Thanks in advance,

PSmith

Additional items: no I did not have FFox open when running; yes I can
access the FFox sqlite db from 3 other programs like SQLite Expert etc. yes
I do need some sleep now so, ciao.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor