Re: Question about Source Control

2014-03-18 Thread Frank Millman

"Frank Millman"  wrote in message 
news:lg6s09$irl$1...@ger.gmane.org...
> Hi all
>
> I know I *should* be using a Source Control Management system, but at 
> present I am not. I tried to set up Mercurial a couple of years ago, but I 
> think I set it up wrongly, as I got myself confused and found it more of a 
> hindrance than a help. Now I am ready to try again, but I want to avoid my 
> earlier mistakes.
>

Many thanks to all for the responses. I have a much better feel for it now. 
If anything, I have moved from being confused because I did not understand 
it, to being confused because there are so many options I am not sure which 
to select. However, I consider this to be progress!

I have decided to stick with Mercurial, simply because that is what I used 
in my previous attempt and I felt comfortable with it. Also I believe that 
Python itself uses it, so if it is good enough for them ...

Before actually plunging in, I would like to summarise what I think I have 
understood, and what steps I propose to take.

I realise now that my initial problem had nothing to do with SCM/VCS, and 
everything to do with my lack of knowledge of basic networking protocols. As 
I understand it now, if I want to share the repository over a network, I can 
choose between SSH and HTTP. I like the following quote from Joel Spolsky -

"The quick-and-dirty way to make a central repository is to use Mercurial's 
built in web-server. ... I'm going to configure the server to allow anybody 
in the world to do anything they want to it. ... Needless to say, this is 
rather unsafe, but if you're on a nice protected LAN at work and there's a 
good firewall and you trust everybody on your LAN, this is reasonably OK."

This describes my situation well, so to keep things simple I will start with 
this.

To recap my basic setup, I have machine A which holds the source directory, 
machine B which is used to edit the program, and machines B and C which are 
both used to run the program.

Initially, to prove that I understand the concept, I propose to install 
Mercurial on all three machines. Machine A will hold the central repository, 
which I will clone onto machines B and C. After editing on B, I will 'push' 
to A, and then from C 'pull' from A to get the latest version.

If this works, I will simplify it to make my life easier. My first thought 
was to remove the clone from machine C and set up an nfs share pointing to 
the working directory on machine A, so I don't need the 'pull' step. Then I 
thought, why not just point to the working directory on machine B, so then I 
can test the changes on C directly, without even having to 'push'. I realise 
that this is defeating the object of version control, but I think it makes 
sense. I will still use version control to maintain a full history of the 
project on machine A.

I appreciated Mark's comments about hosting his project on code.google.com - 
not just the mechanics, but the benefits that he experiences from sharing 
his code. I am actually getting closer to being able to do that with my 
project. Over the last few years I have frequently 'trashed' whole sections 
of my code and rewritten them, which I suspect would not endear me to 
someone attempting to collaborate with me. However, the broad framework is 
starting to settle down now, so I am starting to think about putting it out 
there. Then the question is which hosting service to use - there are so many 
of them. I will probably come back here for more advice when I get to that 
stage.

Frank



-- 
https://mail.python.org/mailman/listinfo/python-list


Greetings from Al-Madinah International University

2014-03-18 Thread marwa kotb
Al Salam Alaykom w rahmat allah w barkato

 
Dear : mr \  mrs
We are pleased that on behalf of the Al-Madinah International University 
[MEDIU] greetings and best wishes for you continued success , coupled with the 
sincere invitations for your further success and development and growth.
 
 
Al-Madinah International University [MEDIU] Malaysia: "University City World 
[MEDIU] Malaysia" is one of the leading universities of Malaysia, which is 
characterized by excellence and excellence of technical and higher education 
areas, and " Al-Madinah International University [MEDIU] " is a multiple 
cultures and areas of study and is based
Malaysia  Shah Alam , Here is a brief history.
1. " Al-Madinah International University [MEDIU]" founded early in 2004 in 
Medinah  Almonowra 
 
2. In 19 / July / 2006, the university received the invitation of the Malaysian 
Ministry of Higher Education for the establishment of the University Centre in 
Malaysia.
 
3. On 20 / July / 2007, the university obtained full license from the Ministry 
of Higher Education Malaysia to be the first international  Malaysian 
University pursuing a systematic distance education using e-learning Targeting 
the  Students from around the world.
 
4. In early of February of 2008 the university began full operation of 
reception of students. 
5. joined the university for beginning of the year 2009, approximately [1500 ] 
students from different countries, while the number of applications submitted 
to the University of [3000] enrollment request.
 
. 6. Early / 2009. University offered more than (24) academic program 
accredited by the Accreditation Authority and the Ministry of Higher Education 
(Malaysia), and more (34) accredited course in Arabic and English language 
center.
 
. 7. Early 2009. Varied the levels of academic programs at the university to 
include foundation studies ,  Pre-university, diploma, bachelor's degree - 
graduate studies, language training courses.
8. Mid-2009. The number of students who were enrolled in the university more 
than (4701) students from more than 40 nationalities around the world.
 
. 9. The third quarter of 2009. The Al-Madinah International University [MEDIU] 
Passed successfully institutional inspection held by the Malaysian Ministry of 
Higher Education to ensure quality of academic and administrative of the 
University.
 
10 . The end of 2009. The number of applications increased by the University of 
(6508) Application from more than (60) countries around the world, while the 
number of students enrolled in the University (2482 )
 
11. The end of 2009.The university Completed the (10) new programs of study for 
approval by the  Malaysian accreditation of Graduate Studies.
 
12. The end of 2009. The Al-Madinah International University [MEDIU] started 
the procedures to start the constituent university education in the disciplines 
of direct scientific and practical, including a new Computer Science, Finance 
and Administration, Engineering and intending to be started by mid-year 2010.
 
13. . Early in 2010. The number of students of the University increased to 
(3057) students from around the world, from the beginning of September  2010.
 
14. The end of 2010. The number of applications received the university for 
direct education on campus system around (511) applications and more than (154) 
enrollment students.
 
15. Early of  2011. The number of applications received by the 
university to direct education on campus system (2312) The number of enrollment 
students  more than (362).
. . 16. Early in 2011. Al-Madinah International University [MEDIU] inclusion 
Programs of the  Al-Madinah International University [MEDIU] in full 
accreditation for four academic graduate programs in the Faculty of Islamic 
Sciences in the list of qualifications recognized by the Civil Service 
Commission, Malaysia
 
17. The end of 2011. The university  the graduating first graduating batch of 
students from the  Al-Medina International University  in the  master's 
programs, bachelor's and (84) students for the bachelor's degree, and (27) 
students for master's degree.
 
 
What distinguishes the Al-Medinah International University [MEDIU].
 
First, high-technical  and modern facilities: The technical infrastructure of 
the Al-Medinah International University  is designed to match the best 
standards in the field of modern e-learning and distance education, including 
those of infrastructure following matters: 
 
Al-Medinah International University website on the Internet "www.mediu.edu.my": 
which offers all university services, which content  admission, registration , 
inquiry , direct access to the lessons and communicate with lecturers  and 
administrators staff of t the university.
 
The electronic system of educational administration "Alim" for managing  the  
academic affairs of  the university, which can be both a student university 
lectures , administrators and supervisors to manage all the  Proce

Re: Question about Source Control

2014-03-18 Thread Chris Angelico
On Wed, Mar 19, 2014 at 1:12 PM, Tim Chase
 wrote:
> On 2014-03-18 21:38, Terry Reedy wrote:
>> At least with hg, one should best test the code in the working
>> directory *before* committing to the local repository.
>
> I don't know if this is a hg-vs-git way of thinking, but I tend to
> frequently commit things on a private development branch regardless
> of brokenness, but once I get it working, I flatten & clean up those
> changes ("rebase" in git terms, which I believe has been adopted as a
> standardly-available-but-not-enabled-by-default module in hg) into
> logical units of change-sets that I then test individually before
> applying them to my more public-facing branch.  This produces clean
> history that makes it easy for others to see what's going on.

My approach to rebasing is derived from the accountancy concepts my
Dad taught me. You create transactions, invoices, whatever, and you
can freely edit them so long as they're the "current batch". It's very
clear what the current batch is and where history begins. Then when
you update that batch, it becomes history and is indelible; if you
find an error in history, you put a new transaction through that
updates it (or maybe reverses it completely, so you can then do a new
clean transaction), which will have its own date (the date of the
correction) and its own identity. [1] In git terms, that means commits
above origin/master are freely editable, but as soon as anything's
pushed, it's not to be changed. I violate that rule only very VERY
occasionally, and only with the understanding that every clone of the
repo will have to be manually updated.

The "git rebase -i" command is perfect for this - it lets you rewrite
anything that isn't pushed yet, by default. I made myself a hook
script that helps with this; between that and the "autosquash" feature
of git rebase interactive, it's easy to fiddle with unpushed changes.
Let's say you discover a typo in an unpushed commit, and go and fix
the corresponding file. As long as it's a one-file edit, and the most
recent edit to that file is the commit you want to fix up, just type:

$ git commit -amf

or

$ git commit some-file -mf

and it'll make a fixup commit marked with that commit's message. Then:

$ git rebase -i

will notice that (if autosquash is enabled) and offer to squash the
two commits together. In all cases, only unpushed commits are
considered; everything from origin/master is untouchable.

If anyone wants the script, I'm happy to share, though it is
git-specific. Porting it to hg (does hg do hooks? I'm sure it must) is
left as an exercise for the reader :)

ChrisA

[1] Linking this in with a previous thread on identity vs value: a
transaction definitely has an identity, which may or may not be
representable with some sort of database ID field. The identity might
be something like "third row of the current batch" and nothing more,
but it has one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Tim Chase
On 2014-03-18 21:38, Terry Reedy wrote:
> At least with hg, one should best test the code in the working
> directory *before* committing to the local repository. 

I don't know if this is a hg-vs-git way of thinking, but I tend to
frequently commit things on a private development branch regardless
of brokenness, but once I get it working, I flatten & clean up those
changes ("rebase" in git terms, which I believe has been adopted as a
standardly-available-but-not-enabled-by-default module in hg) into
logical units of change-sets that I then test individually before
applying them to my more public-facing branch.  This produces clean
history that makes it easy for others to see what's going on.

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list


[no subject]

2014-03-18 Thread Nathan Bruce
Hi I was wondering how much your oxycontins are for what mg and quantity.
Also do you guys sell dilaudid?

Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Terry Reedy

On 3/18/2014 5:51 PM, Gregory Ewing wrote:

Frank Millman wrote:

These are the kind of stumbling blocks that prevented me from
succeeding in my previous attempt. I have a vague recollection that I
set it up on machine A, but then hit a problem because machines B and
C both accessed the same directory, but with different names


For dealing with your practice of editing on one machine and
running on another, you may be best off having just *one* local
repository, residing on the shared file system. Whichever machine
you're working on, you cd to the shared directory and use hg or
git commands from there, so all the pathnames you're using are
relative.


At least with hg, one should best test the code in the working directory 
*before* committing to the local repository. The one local repository 
could still be a close of a master repository somewhere else. One can 
push multiple commits at once, either as the end of a work session or 
when one has done enough to become paranoid about losing work.




--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Steven D'Aprano
On Tue, 18 Mar 2014 15:21:28 -0700, Dan Stromberg wrote:

> On Tue, Mar 18, 2014 at 3:03 PM, Marko Rauhamaa 
> wrote:
>> Dan Stromberg :
>> For a proper comparison, I'd like a fixed, identical dataset and set of
>> operations run against each data structure.
>>
>> How about this test program:
> 
> I used to do essentially this, but it was time-prohibitive and produced
> harder-to-read graphs - harder to read because the enormous values of
> the bad trees were dwarfing the values of the good trees.

A log graph may be the solution to that: graph the log of the time rather 
than time itself.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Steven D'Aprano
On Wed, 19 Mar 2014 01:11:33 +0200, Marko Rauhamaa wrote:

> Dan Stromberg :

>> Rather than throw out unbalanced binary tree altogether, it makes more
>> sense to run it until it gets "too slow".
> 
> I disagree strongly. You should throw out unbalanced binary trees and
> linked lists and the like and concentrate on solid contenders.

If you are in a position to randomize the data before storing it in the 
tree, an unbalanced binary tree is a solid contender. The overhead will 
likely be much less than any balanced tree, and the probability of 
degenerate behaviour negligible for any amount of data big enough to 
really matter.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Chris Kaynor
>
> On Tue, Mar 18, 2014 at 1:55 PM, Marko Rauhamaa  wrote:
>
Dan Stromberg :
>> > The results are at
>> >
>> http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/
>
>

  Size: 1048576, duration:  75.3, dictionary type: dict
> [...]
> Size:  262144, duration:  66.1, dictionary type: AVL_tree
> [...]
> Size:   65536, duration:  77.3, dictionary type: blist.sorteddict
>

Taking a quick look at this, I think it might be made much clearer if the
number/second were added to the output. While it can be computed off the
displayed data, it would make it much easier to compare in the table view
by including it. Something like:

  Size: 1048576, duration:  75.3, dictionary type: 13925/second: dict
  Size:  262144, duration:  66.1, dictionary type: 3965/second: AVL_tree
  Size:   65536, duration:  77.3, dictionary type: 847/second:
blist.sorteddict

Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling buffer alignment in file.read()

2014-03-18 Thread Dan Stromberg
On Tue, Mar 18, 2014 at 1:23 PM, Haralanov, Mitko
 wrote:
> Hi all,
>
> I am using Python to read from a binary device file which requires that all 
> read sizes are in 8byte multiples and the user's buffer is 8byte aligned.
>
> I am currently using a file object and the file.read() method. However, the 
> issue is that the file.read() method allocates the buffer passed to C 
> function under the covers and, therefore, the alignment is arbitrary.
>
> Is there a way that I can get file.read() to use an 8byte aligned buffer?

This is a lot like what my odirect project does:
http://stromberg.dnsalias.org/~strombrg/odirect/

It does buffer alignment, because O_DIRECT requires buffer alignment.
It's a Python-callable SWIG wrapper for some C code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling buffer alignment in file.read()

2014-03-18 Thread Gregory Ewing

Haralanov, Mitko wrote:


The problem is not controlling the number of bytes read. That part seems to
be working. The issue is that the buffer into which the data is placed needs
to be of certain alignment (8byte-aligned). Python does not seem to have a
way that allows me to control that.


Hmmm, that could be tricky. Have you tried using os.read()?
If you're lucky, Python will be using a malloc() call or
equivalent to create a str/bytes object to read the data
into, and that will return something platform-aligned.

If you're unlucky, there's probably no pure-Python
solution, and you might need to write a small C or
Cython module to accomplish this trick.


--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Marko Rauhamaa
Dan Stromberg :

> On Tue, Mar 18, 2014 at 3:03 PM, Marko Rauhamaa  wrote:
>> Dan Stromberg :
>> For a proper comparison, I'd like a fixed, identical dataset and set
>> of operations run against each data structure.
>>
>> How about this test program:
>
> I used to do essentially this, but it was time-prohibitive and
> produced harder-to-read graphs - harder to read because the enormous
> values of the bad trees were dwarfing the values of the good trees.
>
> Imagine doing 1 operation tests for the unbalanced binary
> tree. For a series of random keys, it would do quite well (probably
> second only to dict), but for a series of sequential keys it would
> take longer than anyone would reasonably want to wait because it's
> basically a storage-inefficient linked list.
>
> Rather than throw out unbalanced binary tree altogether, it makes more
> sense to run it until it gets "too slow".

I disagree strongly. You should throw out unbalanced binary trees and
linked lists and the like and concentrate on solid contenders.

But it's your test. You do as you like.

Anyway, even a well-thought-out test is subject to all kinds of
criticisms due to the CPU architecture, the distribution of the key
values, the quality of the data structure implementation etc etc.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Controlling buffer alignment in file.read()

2014-03-18 Thread Haralanov, Mitko
> For control at that level you'd be better off using
> direct system calls, i.e. os.open() and os.read(),
> then you can read exacty the number of bytes you want.
> 

The problem is not controlling the number of bytes read. That part seems to be 
working.
The issue is that the buffer into which the data is placed needs to be of 
certain alignment (8byte-aligned). Python does not seem to have a way that 
allows me to control that.

Thanks,
- Mitko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling buffer alignment in file.read()

2014-03-18 Thread Gregory Ewing

Haralanov, Mitko wrote:

I am using Python to read from a binary device file which requires that all
read sizes are in 8byte multiples and the user's buffer is 8byte aligned.

Is there a way that I can get file.read() to use an 8byte aligned buffer?


For control at that level you'd be better off using
direct system calls, i.e. os.open() and os.read(),
then you can read exacty the number of bytes you want.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Dan Stromberg
On Tue, Mar 18, 2014 at 3:03 PM, Marko Rauhamaa  wrote:
> Dan Stromberg :
> For a proper comparison, I'd like a fixed, identical dataset and set of
> operations run against each data structure.
>
> How about this test program:

I used to do essentially this, but it was time-prohibitive and
produced harder-to-read graphs - harder to read because the enormous
values of the bad trees were dwarfing the values of the good trees.

Imagine doing 1 operation tests for the unbalanced binary
tree. For a series of random keys, it would do quite well (probably
second only to dict), but for a series of sequential keys it would
take longer than anyone would reasonably want to wait because it's
basically a storage-inefficient linked list.

Rather than throw out unbalanced binary tree altogether, it makes more
sense to run it until it gets "too slow".

The workload+interpreter pairs are all tested the same way, it's just
that the ones that are doing badly are thrown out before they're able
to get a lot worse. Studying the graphs will likely help develop an
intuition for what's happening.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Marko Rauhamaa
Dan Stromberg :

> dict was able to do 1048576 operations on a dictionary before taking
> more than 120 seconds to complete - it took 75.3 seconds to do 1048576
> operations.
>
> AVL_tree was able to do 262144 operations on a dictionary before
> taking more than 120 seconds to complete - it took 66.1 seconds to do
> 262144 operations.
>
> blist.sorteddict was able to do 65536 operations on a dictionary
> before taking more than 120 seconds to complete - it took 77.3 seconds
> to do 65536 operations.

For a proper comparison, I'd like a fixed, identical dataset and set of
operations run against each data structure.

How about this test program:

   generate random datasets of 100, 1, 100 and 1 elements
   generate random testset of 100 elements
   for each data structure:
for each dataset:
 initialize data structure with dataset
 head, tail = testset[:100], testset[100:]
 t0 = current timestamp
 for each element in head:
  add element to data structure
 for each element in tail:
  add element to data structure
  append element to head
  remove head.pop(0) from data structure
 for each element in head:
  remove element from data structure
 t1 = current timestamp
 report data structure type, dataset size, t1 - t0


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Gregory Ewing

Frank Millman wrote:
These are the kind of stumbling blocks that prevented me from succeeding in 
my previous attempt. I have a vague recollection that I set it up on machine 
A, but then hit a problem because machines B and C both accessed the same 
directory, but with different names


For dealing with your practice of editing on one machine and
running on another, you may be best off having just *one* local
repository, residing on the shared file system. Whichever machine
you're working on, you cd to the shared directory and use hg or
git commands from there, so all the pathnames you're using are
relative.

Source control operations might be slightly slower that way,
but you'd save time by not having to update your local repo
every time you switch between editing and running, so it may
well be faster overall. In any case, if the machines involved
are on a fast local network, I wouldn't expect there to be
much difference.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Dan Stromberg
On Tue, Mar 18, 2014 at 1:55 PM, Marko Rauhamaa  wrote:
> Dan Stromberg :
>
>> The results are at
>> http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/
>
> Unfortunately I'm having a hard time understanding the results.
>
> The 50/50 get/set ratio is most interesting to me.
>
> I'm seeing (under cpython-3.3):
>
>
> Size: 1048576, duration:  75.3, dictionary type: dict
> [...]
> Size:  262144, duration:  66.1, dictionary type: AVL_tree
> [...]
> Size:   65536, duration:  77.3, dictionary type: blist.sorteddict
>
>
> What does it mean?

dict was able to do 1048576 operations on a dictionary before taking
more than 120 seconds to complete - it took 75.3 seconds to do 1048576
operations.

AVL_tree was able to do 262144 operations on a dictionary before
taking more than 120 seconds to complete - it took 66.1 seconds to do
262144 operations.

blist.sorteddict was able to do 65536 operations on a dictionary
before taking more than 120 seconds to complete  - it took 77.3
seconds to do 65536 operations.

For the 50/50 workload; the "operations" were half adding key, value
pairs; and half lookups of values by keys we know are in the
dictionary.

I used to run all the dictionaries for as long as it took to do 4
million operations, but for (EG) unbalanced binary trees, that would
take far too long in the ordered tests, so I changed the code to try a
given tree type until the time for an operation became prohibitive.

If you look at the graphs (I have to admit they've become a little
cluttered), you can see the slower trees "escaping" rapidly (exceeding
the 120 second threshold), while the better performing trees grow more
slowly and are allowed to continue proving themselves longer.
Inspecting these graphs may help in developing an intuition for how
the tests were conducted.

The code implementing this method of testing is in
http://stromberg.dnsalias.org/svn/python-tree-and-heap-comparison/trunk/tester

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


mobile friendly docs?

2014-03-18 Thread klo uo
Hi,

let me quickly introduce my concern - I was happy to see main
python.org portal rendered nicely on mobile, but docs are still hardly
accessible, while sphinx allows better experience if user instructs it
to.

So I browsed Python MLs (sorry if this is not the right one, I'd be
happy to forward my mail where you suggest) and wanted to ask if such
concern is planed, as I can run Python from years ago on my Nokias,
while feeling strange that official docs aren't accessible from
mobile.


TIA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Marko Rauhamaa
Dan Stromberg :

> The results are at
> http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/

Unfortunately I'm having a hard time understanding the results.

The 50/50 get/set ratio is most interesting to me.

I'm seeing (under cpython-3.3):


Size: 1048576, duration:  75.3, dictionary type: dict
[...]
Size:  262144, duration:  66.1, dictionary type: AVL_tree
[...]
Size:   65536, duration:  77.3, dictionary type: blist.sorteddict 


What does it mean?


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Dave Angel
 Steven D'Aprano  Wrote in
 message:
> On Tue, 18 Mar 2014 19:08:17 +1100, Chris Angelico wrote:
> 
>> On Tue, Mar 18, 2014 at 6:55 PM, Steven D'Aprano 
>> wrote:
>>> I don't think that *version* control is the right model to describe
>>> what hg and git do, although it may be appropriate for subversion. hg
>>> doesn't manage *versions*, it manages changes to source code
>>> ("changesets").
>> 
>> Meh... Is there any real difference? 
> 
> If you believe Joel Spolsky, there is:
> 
> http://hginit.com/00.html
> 
> Scroll down about half way, to the section titled "One more big 
> conceptual difference".
> 
> Recording *snapshots* versus recording *diffs* makes a considerable 
> difference when it comes to dealing with merge conflicts.
> 

So which does git do, according to this model? 


-- 
DaveA

-- 
https://mail.python.org/mailman/listinfo/python-list


Controlling buffer alignment in file.read()

2014-03-18 Thread Haralanov, Mitko
Hi all,

I am using Python to read from a binary device file which requires that all 
read sizes are in 8byte multiples and the user's buffer is 8byte aligned.

I am currently using a file object and the file.read() method. However, the 
issue is that the file.read() method allocates the buffer passed to C function 
under the covers and, therefore, the alignment is arbitrary.

Is there a way that I can get file.read() to use an 8byte aligned buffer?

Thanks,
- Mitko


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unexpected comparisons in dict lookup

2014-03-18 Thread Ian Kelly
On Tue, Mar 18, 2014 at 8:20 AM, Steven D'Aprano
 wrote:
> I stumbled across this unexpected behaviour with Python 2.7 and 3.3. When
> you look up a key in a dict, the key is sometimes compared against other
> keys twice instead of just once.

>From what I can see in the code, it adds a perturbation based on the
upper bits of the hash value to the probing scheme, to reduce
collisions for keys with unequal hashes.  On the downside, this
cancels the guarantee that each bucket can only be checked at most
once.  The perturbation gradually shifts to 0 after a few iterations,
so every bucket can still be reached within O(n) iterations.

See the comments starting at "Major subtleties ahead":
http://hg.python.org/cpython/file/f8b40d33e45d/Objects/dictobject.c#l106
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Dan Stromberg
On Mon, Mar 17, 2014 at 3:05 PM, Marko Rauhamaa  wrote:
> Joshua Landau :
>
>> The thing we really need is for the blist containers to become stdlib
>> (but not to replace the current list implementation).
>
> Very interesting. Downloaded blist but didn't compile it yet. It *could*
> be the missing link.
>
> I would *love* to see some comparative performance results between
> blist.sorteddict and an AVL tree.

I added blist.sorteddict and removed (temporarily) Pypy and Jython.
The results are at
http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/

In short, blist.sorteddict didn't do that well, despite being in C.
In the random workloads, blist.sorteddict was dead last.  In the
sequential workloads blist.sorteddict fell somewhere in the middle.

I excluded Pypy and Jython because blist.sorteddict probably doesn't
run on them.

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extract stream title from the output of mplayer

2014-03-18 Thread Jabba Laci
> Python. (Or s/guess/hop/ if you prefer!) There are many ways this
> could be done; what have you tried, what partly worked, what did
> something unexpected?

Hi,

I managed to solve the problem. In the man of mplayer I found how to
quit after X seconds: "-endpos X". See my solution below.

Best,

Laszlo



import re
import shlex
from subprocess import PIPE, Popen

URL = 'http://relay2.slayradio.org:8000/'


def get_exitcode_stdout_stderr(cmd):
"""
Execute the external command and get its exitcode, stdout and stderr.
"""
args = shlex.split(cmd)

proc = Popen(args, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
exitcode = proc.returncode
#
return exitcode, out, err


def get_title():
cmd = "mplayer -endpos 1 -ao null {url}".format(url=URL)
out = get_exitcode_stdout_stderr(cmd)[1]

for line in out.split("\n"):
#print(line)
if line.startswith('ICY Info:'):
match = re.search(r"StreamTitle='(.*)';StreamUrl=", line)
title = match.group(1)
return title

def main():
print(get_title())
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extract stream title from the output of mplayer

2014-03-18 Thread Chris Angelico
On Wed, Mar 19, 2014 at 4:03 AM, Jabba Laci  wrote:
> I have a simple command-line radio player and I want to extract song
> titles from the output of mplayer.
>
> ICY Info: StreamTitle='Alexander 'Taxim' Nev - Unsound minds feat.
> SAM';StreamUrl='http://www.SLAYRadio.org/';
>
> At the end it shows a progress indicator, thus the output is streamed.
> The problem is I can't get this output in a string. My idea is to
> launch mplayer with a timeout of 2 seconds for instance, get the
> produced output and find the line that starts with "ICY Info". But
> when I kill the process after the timeout, I don't know how to fetch
> the output produced so far.

My first recommendation would be to see what you can get directly,
rather than calling on mplayer. But otherwise, what you want to do is
redirect the output somewhere. Are you using the Python subprocess
module to do this? You haven't shown any code, but since you posted
this to python-list I'm guessing that you probably are talking about
Python. (Or s/guess/hop/ if you prefer!) There are many ways this
could be done; what have you tried, what partly worked, what did
something unexpected?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Mark H Harris

On 3/17/14 8:06 AM, Frank Millman wrote:

All my source code resides on an old Linux server, which I switch on in the
morning and switch off at night, but otherwise hardly ever look at. It uses
'samba' to allow sharing with Windows, and 'nfs' to allow sharing with other
Linux machines.


hi Frank, I am using GIT and code.google.com.

   https://code.google.com/p/pythondecimallibrary/

   I have not used Code Google prior to the pdeclib project; however, I 
plan to use it in the future extensively, at least for my open source 
projects (and when I am thinking about bringing another person on board.


   Code Google permits three version|control|access systems (I use GIT, 
a very simple command line interface).  The thing is that the code 
resides on a person's machine as a clone of the repository, and is 
assessable from anywhere in the world, allows multiple developer 
participation, allows multiple branches|merge|master, and allows access 
to the source on-line (browse|edit), and permits new members to clone 
the repository from anywhere.  Downloads are zipped.


   The down-side is also the up-side. Code Google is an open source 
developer collaborative environment for sharing & managing. Anything you 
put there belongs to everyone in the project, and can be viewed by 
anyone in the world (which is kinda the point of open source).  There is 
a supreme benefit to having multiple eyes on the code. People maybe not 
even involved in the project directly will comment on the code (and they 
are not shy). You code will improve dynamically and radically (if you 
have the guts for it).


   It took me a couple of hours to get up to speed with Code Google. It 
took another hour or so to come up to speed with GIT. You need to create 
the project on Code Google first. Then on your machine, in the code 
directory (the directory actually holding the source files that you are 
going to make a part of your project) you do these things:


   git init
   this builds the .git subdirectory needed for push

   git add file-name

   add each filename you want to commit and push

   git remove

   removes any unwanted files

   git commit -a

   edit your commit comments here ,  or provide default


   git push  https://code.google.com/p/whateveryourprojectnameis/ master

   sends the files on their way


   other files:.gitconfig.netrc


   You will place your name, email, and method (use simple) in the 
.gitconfig file.  The .netrc file will contain the login info for code 
google machine.



   Read the GIT manual on-line; its pretty easy too.

   https://www.kernel.org/pub/software/scm/git/docs/user-manual.html

   http://git-scm.com/documentation


Cheers



--
https://mail.python.org/mailman/listinfo/python-list


extract stream title from the output of mplayer

2014-03-18 Thread Jabba Laci
Hi,

I have a simple command-line radio player and I want to extract song
titles from the output of mplayer.

Example:

$ mplayer http://relay2.slayradio.org:8000/

It produces a streamed output of this form:

MPlayer2 UNKNOWN (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
...
ICY Info: StreamTitle='Alexander 'Taxim' Nev - Unsound minds feat.
SAM';StreamUrl='http://www.SLAYRadio.org/';
...

At the end it shows a progress indicator, thus the output is streamed.
The problem is I can't get this output in a string. My idea is to
launch mplayer with a timeout of 2 seconds for instance, get the
produced output and find the line that starts with "ICY Info". But
when I kill the process after the timeout, I don't know how to fetch
the output produced so far.

Thanks,

Laszlo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HOLY SH*T! HUMANS ORIGINATED IN THE DEVONIAN

2014-03-18 Thread Danyelle Davis
Don't feed the trolls.  Actually talking to it makes it think you actually
care..


On Mon, Mar 17, 2014 at 4:50 AM, ASSODON  wrote:

> ===
> >BREAKING NEWS
> ===
> >
> RICHARD LEAKEY JUST DIED DUE TO HEART FAILURE!
> >
> THE REASONS DESCRIBED BY THE MEDICAL TEAM IS THAT HIS WORK WAS
> DISPROVEN, BY NONE OTHER THAN YOUR OWN BASTARD, THRINAXODON.
> >
> THIS CAUSED LEAKEY'S HEART TO EXPLODE!
> >
> THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000!
> >
> TO WASTE YOUR TIME EVEN FURTHER, CHECK OUT THESE LINKS BELOW.
> ===
> EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:
>
> https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa
> d/6f501c469c7af24f#
>
>
> https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa
> d/3aad75c16afb0b82#
>
>
> 
>
> http://thrinaxodon.wordpress.com/
>
> ===
>
> THRINAXODON ONLY HAD THIS TO SAY:
>
> "I..I...I...Can't believe it. This completely disproved Darwinian
> orthodoxy."
>
> ===
>
> THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING
> WITH FEAR.
>
> ===
> THESE ASSHOLES ARE GOING TO DIE:
> THOMAS AQUINAS;
> ALDOUS HUXLEY;
> BOB CASANVOVA;
> SkyEyes;
> DAVID IAIN GRIEG;
> MARK ISAAK;
> JOHN HARSHAM;
> RICHARD NORMAN;
> DR. DOOLITTLE;
> CHARLES DARWIN;
> MARK HORTON;
> ERIK SIMPSON;
> HYPATIAB7;
> PAUL J. GANS;
> JILLERY;
> WIKI TRIK;
> THRINAXODON;
> PETER NYIKOS;
> RON OKIMOTO;
> JOHN S. WILKINS
> ===
>
> THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A
> HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT
> THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD
> TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY
> FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep
> people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS
> SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That
> is a myth, for people to believe in science." THRINAXODON PLANS TO
> BRING DOOM TO SCIENCE, ITSELF.
>
> 
>
> THRINAXODON IS NOW ON REDDIT
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'complex' function with string argument.

2014-03-18 Thread Mark H Harris

On 3/17/14 11:52 PM, Steven D'Aprano wrote:

On Mon, 17 Mar 2014 11:18:56 -0500, Mark H Harris wrote:

 Who knows, beats me.



With respect, that's just because you would make a lousy language
designer :-)


   Ouch;-)


"How should one spell a complex number?" There is perfectly good syntax
for complex numbers used by mathematicians and engineers for over a
century. There is no need to invent something different just for the sake
of being different:
 Yes:   2+3i or 2+3j


   Yes.  my Q was rhetorical only. And for the sake of discussion, 
particularly on the part of the OP, to think about what one expects 
based on experience and common sense, as a mathematician. (that doesn't 
mean it will be easy for the lexical parser.



"Should we use i or j ?" There are good reasons for both i and j. This
one comes down to personal preference.


   no, not really.  nobody writes,   e^(jPI) + 1 = 0

   Euler wants to see   e^(iPI) + 1 = 0  ;-)


"Should the imaginary part be set off somehow?" What do you mean "set
off"? Why do you want to? Since the imaginary part can appear on its own:


   simply, is 2j a literal complex part?  ...yes 2 j  ...no

   In other words, there must NEVER be a space between the 2 and j. 
This is debatable:   3 +2jalthough, I want to see3+2j




 z = 2 + 3j  # an expression adding 2 to 3j
 z = 5*3j  # an expression multiplying 5 by 3j


   all good, well until its not


How flexible should the complex constructor be? Should it bend over
backwards to accept any mathematical expression that includes a complex j
suffix, e.g. complex("2**3i")? I think not,


   I think not either.  But, it is possible to have *many* constructors/

   But, really, how often is this a problem?   like almost never!


  >>>  complex( 3   +2j  )
(3+2j)
  >>>
I don't know... you tell me.


In both cases, the call to complex is redundant. You've already created a
complex number, using syntax, then you pass it to the complex function
which just returns the same number.


   Of course.  I was merely pointing out that the constructor for 
'literals' (whatever you guys mean by that) is 'different' than the 
consistency with the string constructor.  As Chris pointed out these are 
two markedly different animals; one is a valid parse syntax, the other 
is a string constructor.   But here is my point--- to the user the 
difference comes down to semantics, which is not really true.


cf. below


  >>>  complex('3+2j')
(3+2j)
  >>>  complex('3 +2j')
Traceback (most recent call last):
File "", line 1, in
  complex('3 +2j')
ValueError: complex() arg is a malformed string




Also, philosophically, C ignores white space;  python does not.


   This was said tongue in cheek...  *both* languages inconsistently 
observer (and ignore) white space!  But, in general, white space is more 
important to python, and less important to C.


I'm still hung up on whether I'm a lousy language designer.  I guess 
we'll know if people use my language (or not)!  I suppose they might use 
it even though its lousy; on the other hand, it might be too simple for 
folks to be able to figure it out.   :)


marcus
--
https://mail.python.org/mailman/listinfo/python-list


Re: HOLY SH*T! HUMANS ORIGINATED IN THE DEVONIAN

2014-03-18 Thread Juha Nieminen
In comp.lang.c++ ASSODON  wrote:
> THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000!

I find it interesting, from a psychological perspective, that you are
not even *pretending* that you are not lying and making stuff up.
You pretty much imply it as clearly as it possibly can be, and clearly
don't care. Yet, nevertheless, you accuse others of lying.

I don't think you are simply a troll who does this for his own amusement,
because even trolls get tired of the same old joke, and move to other
things. I get a feeling of this being more obsessive in nature.

There's something probably very wrong inside your head. I really think
you should seek professional help for your mental problems.

--- news://freenews.netfront.net/ - complaints: n...@netfront.net ---
-- 
https://mail.python.org/mailman/listinfo/python-list


Unexpected comparisons in dict lookup

2014-03-18 Thread Steven D'Aprano
I stumbled across this unexpected behaviour with Python 2.7 and 3.3. When 
you look up a key in a dict, the key is sometimes compared against other 
keys twice instead of just once.

First, a class that reports when it is being tested for equality, with a 
fixed hash so that we get collisions inside the dict:

class Spam:
def __init__(self, label):
self.label = label
def __str__(self):
return self.label
def __hash__(self):
return 100
def __eq__(self, other):
print("comparing %s with %s" % (self, other))
return self is other


Create a dict and prepare for collisions:

x = Spam("x")
y = Spam("y")
d = {100: 1}  # hash(100) == 100


When we add x to the dict, it collides with the existing key 100, so I 
expect one call to Spam.__eq__, and that's exactly what I get:

py> d[x] = 200
comparing x with 100


But when I try adding y to the dict, it collides with 100, then it 
collides with x, then it apparently collides with x a second time:

py> d[y] = 300
comparing y with 100
comparing x with y
comparing x with y


I expected only two calls to __eq__, not three: first comparing with 100, 
then comparing with x. Checking for keys gives the same result:

py> x in d
comparing x with 100
True
py> y in d
comparing y with 100
comparing x with y
comparing x with y
True


What's more, checking for a key which is not present also compares three 
times instead of twice:

py> Spam("z") in d
comparing z with 100
comparing x with z
comparing x with z
comparing y with z
False


I expected it to compare z with 100, then x *once*, then y, then return 
False.

Why is the dict lookup comparing against x twice? It doesn't seem to be 
the fault of x. If I create a slightly different dict, with the 
collisions in a different order:

py> e = {x: 100}
py> e[100] = 200
comparing x with 100
py> e[y] = 300
comparing x with y
comparing y with 100
comparing y with 100



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'complex' function with string argument.

2014-03-18 Thread Marko Rauhamaa
Christian Gollwitzer :

> The same problem arises with unary minus, but it's less annoying
> because -(a*b) = (-a)*b.

  >>> -1**2
  -1


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Steven D'Aprano
On Tue, 18 Mar 2014 19:08:17 +1100, Chris Angelico wrote:

> On Tue, Mar 18, 2014 at 6:55 PM, Steven D'Aprano 
> wrote:
>> I don't think that *version* control is the right model to describe
>> what hg and git do, although it may be appropriate for subversion. hg
>> doesn't manage *versions*, it manages changes to source code
>> ("changesets").
> 
> Meh... Is there any real difference? 

If you believe Joel Spolsky, there is:

http://hginit.com/00.html

Scroll down about half way, to the section titled "One more big 
conceptual difference".

Recording *snapshots* versus recording *diffs* makes a considerable 
difference when it comes to dealing with merge conflicts.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 html.parser

2014-03-18 Thread Peter Otten
balaji marisetti wrote:

> Hi,
> 
> I'm trying to parse a pice of HTML code using `html.parser` in Python3.
> I want to find out the offset of a particular end tag (let's say ) and
> then stop processing
> the remaining HTML code immediately. So I wrote something like this.
> 
> [code]
> def handle_endtag(self, tag):
> if tag == mytag:
> #do something
> self.reset()
> [code]
> 
> I called `reset()` method at the end of  `handle_endtag()` method. Now the
> problem is: when I call parser.feed("some html"), it's giving an
> "AssertionError" exception. Isn't the `reset()` method
> supposed to be called inside "handler" methods?

Obviously not ;) After looking into the code I think there is no controlled 
way to stop parsing. I suggest that you raise a custom exception instead:

import html.parser

class TagFound(Exception):
pass

class MyParser(html.parser.HTMLParser):
def handle_endtag(self, tag):
if tag == wanted_tag:
raise TagFound

wanted_tag = "a"
parser = MyParser()
for data in ["",
 ""]:
try:
parser.feed(data)
except TagFound:
print("tag {!r} found".format(wanted_tag))
else:
print("tag {!r} not found".format(wanted_tag))
parser.reset()


-- 
https://mail.python.org/mailman/listinfo/python-list


Python3 html.parser

2014-03-18 Thread balaji marisetti
Hi,

I'm trying to parse a pice of HTML code using `html.parser` in Python3.
I want to find out the offset of a particular end tag (let's say ) and
then stop processing
the remaining HTML code immediately. So I wrote something like this.

[code]
def handle_endtag(self, tag):
if tag == mytag:
#do something
self.reset()
[code]

I called `reset()` method at the end of  `handle_endtag()` method. Now the
problem is: when I call parser.feed("some html"), it's giving an
"AssertionError" exception. Isn't the `reset()` method
supposed to be called inside "handler" methods?

Thanks,
Balaji
-- 
:-)balaji
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find and replace multiple RegEx search expressions

2014-03-18 Thread Peter Otten
Jignesh Sutar wrote:

> Hi,
> 
> I'm trying to delete contents of a .txt log file, matching on multiple
> re.sub criteria but not sure how to achieve this.
> 
> Below is an illustration of what I am trying to achieve (of course in this
> example I can combine the 3 re.sub into a single re expression but my
> actual code will have a dozen plus expression I need to match on so easier
> to keep them separate). Only the last re.sub will take effect in the
> example below I need all 3 to take effect.
> 
> 
> import re
> o = open(r"c:\temp\outputfile.txt","w")
> data = open(r"C:\Temp\infile.txt").read()
> o.write( re.sub(".* ","",data) )
> o.write( re.sub(".* ","",data) )
> o.write( re.sub(".* ","",data) )
> o.close()

Apply all substitutions to data before you write the result to the file:

with open(infile) as f:
data = f.read()

for expr in list_of_regexes:
data = re.sub(expr, "", data)

with open(outfile, "w") as f:
f.write(data)


-- 
https://mail.python.org/mailman/listinfo/python-list


Find and replace multiple RegEx search expressions

2014-03-18 Thread Jignesh Sutar
Hi,

I'm trying to delete contents of a .txt log file, matching on multiple
re.sub criteria but not sure how to achieve this.

Below is an illustration of what I am trying to achieve (of course in this
example I can combine the 3 re.sub into a single re expression but my
actual code will have a dozen plus expression I need to match on so easier
to keep them separate). Only the last re.sub will take effect in the
example below I need all 3 to take effect.


import re
o = open(r"c:\temp\outputfile.txt","w")
data = open(r"C:\Temp\infile.txt").read()
o.write( re.sub(".* ","",data) )
o.write( re.sub(".* ","",data) )
o.write( re.sub(".* ","",data) )
o.close()


Thanks in advance.
Jignesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Venus / GuthVenus for iPhone, Nexus, Droid and Android Jelly Bean

2014-03-18 Thread Chris Angelico
On Tue, Mar 18, 2014 at 2:45 PM, Brad Guth  wrote:
> You may want to revise that manifesto to read 'suffer and pay dearly'
> instead of "GOING TO DIE", unless you meant via natural causes.

Don't bother responding to Thrinaxodon, it's a spammer.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'complex' function with string argument.

2014-03-18 Thread Christian Gollwitzer

Hi Steven,

Am 18.03.14 09:00, schrieb Steven D'Aprano:

On Tue, 18 Mar 2014 08:04:44 +0100, Christian Gollwitzer wrote:


Am 15.03.14 17:26, schrieb Jayanth Koushik:

This is regarding the inbuilt 'complex' function. The python docs say:
"Note: When converting from a string, the string must not contain
whitespace around the central + or - operator. For example,
complex('1+2j') is fine, but complex('1 + 2j') raises ValueError."


It's funny that you ask this question exactly now; because I'm currently
implementing a compiler for a small language that understands complex
numbers. As others have explained, the basic issue is the question how
to parse an expression like

1+2i*3

is it "complex(1+2i) times 3"


Putting my mathematician's hat on, I would say *absolutely not*.


or is it sum of 1 and product of complex 2i and 3?


This one. Multiplication has higher precedence than addition, so 1+2i*3
has to be evaluated as 1+(2i*3).


The question was not whether the expression should be interpreted the 
first way, I'm sorry for being unclear. The question was how to 
implement this in a compiler. Because if you implement complex literals 
in the tokenizer, you would end up with the tokens of the first 
interpretation. But if you implement as imaginary literals, then your 
parse tree for "1+2i" ends up as a sum of a real and an imaginary 
literal, instead of a complex literal. This works, but it lets your 
parse tree grow and possibly generates inefficient code. The answer I 
got here, is to parse it as a sum and let the optimizer combine it back 
into a single complex constant.



The same problem arises with unary minus, but it's less annoying because 
-(a*b) = (-a)*b.


I admit that my knowledge of compiler construction is limited, and I'm 
working on my first real-world application now. Oh, and it's not written 
in Python.


Christian


--
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Chris Angelico
On Tue, Mar 18, 2014 at 6:55 PM, Steven D'Aprano  wrote:
> I don't think that *version* control is the right model to describe what
> hg and git do, although it may be appropriate for subversion. hg doesn't
> manage *versions*, it manages changes to source code ("changesets").

Meh... Is there any real difference? With git, I can check out any
tree state I like ("give me the 50th parent of the current HEAD"), so
in that sense it effectively stores versions - at least, it can
retrieve or recreate versions. Does it store versions and optimize
them by recording only the difference, or record differences and
replay them to recreate a state? Two sides of the same coin.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'complex' function with string argument.

2014-03-18 Thread Steven D'Aprano
On Tue, 18 Mar 2014 08:04:44 +0100, Christian Gollwitzer wrote:

> Am 15.03.14 17:26, schrieb Jayanth Koushik:
>> This is regarding the inbuilt 'complex' function. The python docs say:
>> "Note: When converting from a string, the string must not contain
>> whitespace around the central + or - operator. For example,
>> complex('1+2j') is fine, but complex('1 + 2j') raises ValueError."
> 
> It's funny that you ask this question exactly now; because I'm currently
> implementing a compiler for a small language that understands complex
> numbers. As others have explained, the basic issue is the question how
> to parse an expression like
> 
>   1+2i*3
> 
> is it "complex(1+2i) times 3" 

Putting my mathematician's hat on, I would say *absolutely not*.

> or is it sum of 1 and product of complex 2i and 3? 

This one. Multiplication has higher precedence than addition, so 1+2i*3 
has to be evaluated as 1+(2i*3).


-- 
Steve
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Steven D'Aprano
On Tue, 18 Mar 2014 17:47:51 +1100, Ben Finney wrote:

> "Frank Millman"  writes:
> 
>> I feel that I have just not grasped the basics yet, so any assistance
>> that puts me on the right path is appreciated.
> 
> Here is “Hg Init”, a tutorial for Mercurial http://hginit.com/>.
> 
> (“source control” is not the most common term for this; what we're
> talking about is a “version control system”, or VCS. But some Git users
> may disagree.)

I don't think that *version* control is the right model to describe what 
hg and git do, although it may be appropriate for subversion. hg doesn't 
manage *versions*, it manages changes to source code ("changesets"). 
Mercurial describes itself as a "distributed source control management 
tool", so I think the term "source control" is quite appropriate.

http://mercurial.selenic.com/


-- 
Steve
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ordering in the printout of a dictionary

2014-03-18 Thread Chris Angelico
On Tue, Mar 18, 2014 at 6:36 PM, Marc Christiansen
 wrote:
> I would say using pprint.pprint is even easier and it works with your
> failing example:
>
 pprint.pprint({True:1,"Hello":2})
> {True: 1, 'Hello': 2}
>

True. I could try to say that I prefer to offer the simpler approach
rather than encourage people to automatically reach for the nearest
hammer and hope it's right, but the fact is... I completely forgot
about pprint :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Balanced trees

2014-03-18 Thread Joshua Landau
On 18 March 2014 01:01, Daniel Stutzbach  wrote:
> I would love to have include macro-benchmarks.  I keep waiting for the PyPy
> benchmark suite to get ported to Python 3...

*grins*

>> "Delete a slice" is fudged from its inclusion of multiplication, which
>> is far faster on blists. I admit that it's not obvious how to fix
>> this.
>
> I could move the initialization into the timed part, similar to what I did
> for sort (see below).  That has downsides too, of course, but it might be an
> improvement.

You could try making a baseline and subtracting it:

timer("del x[len(x)//4:3*len(x)//4]; x *= 2") - timer("x * 2")

Not ideal, but closer, assuming that the multiplication isn't much
larger than the deletion. Error would be summed.

>> "Sort *" are really unfair because they put initialisation in the
>> timed part
>
> That's a limitation of timeit.  The setup step is only executed once.  If I
> put the initialization there, every sort after the first one would be
> sorting a pre-sorted list.  If you compare the "Create form an iterator" and
> "Sort a random list", you'll see that the initialization cost is dwarfed by
> the sorting cost for n > 15 or so.

This argument is slightly less convincing without the overhead of the
keys. It might be worth doing a subtraction and adding some error-bars
as I suggest above. Nevertheless, I do agree for n > some small n,
which is all that matters anyway.

>> and all have keys.
>
> If you use classes with __lt__ methods instead of keys, the cost is
> dominated by the calls to __lt__.  You're right that I should include both,
> though.

This argument doesn't make sense to me. The only time this happens is
when you have a non-primitive and your transformation gives a
primitive which has optimised comparisons. This typically only happens
when the key is a getitem or getattr, in which case it's just
meaningless overhead. I see little reason to care about the key's cost
in those cases.

> That's definitely a cache issue, which is always a risk with
> micro-benchmarks.
>
> I agree it's more interesting to pick items randomly instead of always
> querying the same index.  The overhead of choice() is kind of a problem,
> though.  Since I'm only plotting up to 10**5, I'd expect these to look more
> or less flat.

You could try jumping around to avoid the cache without using random
numbers. Something like "idx = (idx + LARGE_PRIME) % n" might have less
overhead. Further, the subtraction method would probably work fine for
that.

Also, I don't think the cache is all bad. Chances are a lot of list
accesses have a lot of data locality.

> Thanks for all of the feedback.

Thanks in turn for the module :).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ordering in the printout of a dictionary

2014-03-18 Thread Marc Christiansen
Chris Angelico  wrote:
> On Tue, Mar 18, 2014 at 11:32 AM, Mok-Kong Shen
>  wrote:
>> Is there a way to force a certain ordering of the printout or else
>> somehow manage to get at least a certain stable ordering of the
>> printout (i.e. input and output are identical)?
> 
> Yes; instead of simply printing it out (which calls repr()),
> explicitly iterate over it, like this:
> 
> def display(d):
>return '{'+','.join('%r: %r'%(key,d[key]) for key in sorted(d))+'}'
> 
[...]
> At least, it's consistent as long as the keys all sort consistently,
> which they will if you use simple strings. Other types of keys may not
> work, and in fact mixing types may cause an exception:
> 
 print(display({True:1,"Hello":2}))
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "", line 2, in display
> TypeError: unorderable types: str() < bool()
> 
> But for strings, this is the easiest way to get what you're looking for.

I would say using pprint.pprint is even easier and it works with your
failing example:

>>> pprint.pprint({True:1,"Hello":2})
{True: 1, 'Hello': 2}

Ciao
Marc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Chris Angelico
On Tue, Mar 18, 2014 at 5:47 PM, Ben Finney  wrote:
> (“source control” is not the most common term for this; what we're
> talking about is a “version control system”, or VCS. But some Git users
> may disagree.)

People use different terms depending on their backgrounds, I think.
I've heard a good few words used to describe fundamentally the same
thing, and none is really perfect.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Frank Millman

"Ben Finney"  wrote in message 
news:85y508roiw@benfinney.id.au...
> "Frank Millman"  writes:
>
>> I feel that I have just not grasped the basics yet, so any assistance 
>> that
>> puts me on the right path is appreciated.
>
> Here is "Hg Init", a tutorial for Mercurial http://hginit.com/>.
>
> ("source control" is not the most common term for this; what we're
> talking about is a "version control system", or VCS. But some Git users
> may disagree.)
>

Thanks, Ben, that is a really nice tutorial.

I was calling it an SCM because that is how Mercurial describes it - from 
their home page "Mercurial is a free, distributed source managment control 
tool". I do agree that 'version control' makes more sense.

Frank



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'complex' function with string argument.

2014-03-18 Thread Chris Angelico
On Tue, Mar 18, 2014 at 6:04 PM, Christian Gollwitzer  wrote:
> As others have explained, the basic issue is the question how to parse an
> expression like
>
> 1+2i*3
>
> is it "complex(1+2i) times 3" or is it sum of 1 and product of complex 2i
> and 3?

The only way to have it be the former would be to mandate that all
complex literals have both parts, and you'd still lose clarity. You'd
probably want to have some other symbol rather than + in there, to
emphasize the connection:

1_2j
1_--2j # Negative imaginary component

Otherwise, yeah, do what Python does and have imaginary literals only.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-18 Thread Chris Angelico
On Tue, Mar 18, 2014 at 5:42 PM, Frank Millman  wrote:
> Excuse my ignorance, but how does it actually work?

Ignorance not only excused, but welcomed. :) However, caveat: I know
how git is set up, but not hg. Someone else can fill in the details;
for now, I'll explain git and hope that hg is broadly similar. I
expect it will be.

> Do you set up some kind of client/server relationship, and if so, how do the
> clients (machines B and C) access the software on machine A?

For read-only access, git can run its own protocol, but for read/write
it's most common to run it over SSH. Every pull or push is implemented
by git calling on ssh to run either 'git send-pack' or 'git
receive-pack' on the other end. (It's common to set it up with a
restricted shell that can *only* run those commands, although I also
find this usage convenient for cloning between two computers that I
control, rather than fetching from upstream. It's immensely faster
downloading something over a virtualized gigabit ethernet link than
over the internet!)

So it goes by the rules of SSH. There's a user account on the target
computer, which owns all the files in the repository. That user
account might have a password on it (which you type in every time you
pull/push), or you might use public/private keys to authenticate, or
whatever else you've set up. That part isn't git's responsibility. On
Linux systems, it's usually pretty easy to set up openssh and a
dedicated account; on other servers, I assume it can't be hard to get
something going.

> I know that Mercurial can run its own web server, and clients can access it
> through http. It that what you are suggesting? That would be quite a change
> for me, as on my linux box I do all my work from the command line on a
> console.

You'd still do everything from the command line. You type "git clone
blahblah" or "hg clone blahblah", and everything happens under the
covers. The only way you'd know the difference is if the "blahblah"
part identifies the protocol (which it usually will, but that's
somewhat beside the point).

> These are the kind of stumbling blocks that prevented me from succeeding in
> my previous attempt. I have a vague recollection that I set it up on machine
> A, but then hit a problem because machines B and C both accessed the same
> directory, but with different names - on Windows, a mapped drive and on
> linux a mounted nfs directory. I had to provide a 'path' name to set up
> Mercurial in the first place, but I could not find one that suited both
> clients.
>
> I feel that I have just not grasped the basics yet, so any assistance that
> puts me on the right path is appreciated.

Yeah, a distributed repository solves that. You could have three
entirely different path names on the three computers, and nothing will
care. (You have to be careful to use relative paths everywhere
internally, of course, but you probably do that already.) It's pretty
efficient once you get used to it; I recommend poking around on the
internet for a git tutorial or an hg tutorial, depending on which you
go with. It's not too hard, but there are a lot of commands to keep
track of. Here's a helpful quick reference to the differences between
the two:

https://github.com/sympy/sympy/wiki/Git-hg-rosetta-stone

As a git-familiar and hg-novice, I keep that handy every time I'm
working with hg on anything more complicated than "keep up with the
changes".

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'complex' function with string argument.

2014-03-18 Thread Christian Gollwitzer

Am 15.03.14 17:26, schrieb Jayanth Koushik:

This is regarding the inbuilt 'complex' function. The python docs
say: "Note: When converting from a string, the string must not
contain whitespace around the central + or - operator. For example,
complex('1+2j') is fine, but complex('1 + 2j') raises ValueError."


It's funny that you ask this question exactly now; because I'm currently 
implementing a compiler for a small language that understands complex 
numbers. As others have explained, the basic issue is the question how 
to parse an expression like


1+2i*3

is it "complex(1+2i) times 3" or is it sum of 1 and product of complex 
2i and 3? The answer that python does it by parsing imaginary literals 
and then combining them back using peephole optimization was helpful, 
thanks for that!


Christian
--
https://mail.python.org/mailman/listinfo/python-list