Re: [Tutor] Questions (and initial responses) on using version control: Why cannot I push my single (master) branch to origin without an error occurring?

2015-05-01 Thread Albert-Jan Roskam via Tutor


On Fri, May 1, 2015 6:21 AM CEST Alex Kleider wrote:

>On 2015-04-30 20:39, boB Stepp wrote:
>> I created my remote repository on, say my C-drive, with "git init". I
>> then copied and pasted a file to that location and put it under
>> version control with "git add filename.py". Next I went to my E-drive,
>> which is where I intend to be my working directories. After setting up
>> a similar directory structure (/Projects/), I typed "git clone
>> C:/Projects/project_name" and the desired result appeared on E:
>> E:/Projects/project_name/filename.py. All seemed well with the world!
>> 
>> Now I made some edits to filename.py in my working directory,
>> added/committed and then attempted to push to the remote repository
>> and got this:
>
>I would suggest the following work flow to set up two parallel repositories:
>
>cd 
>git init
>
>git add 
>git commit
>
>cd 
>git clone 
># the above command brings in a copy of all that was committed in the first 
>repo.
>
>Once this is done, I believe your subsequent commits can be pushed without the 
>errors.

I recently did this by creating an alias:
git config alias.pushall '!git push origin devel && git push github devel

So you can use 'git pushall'. The other method mentioned on SO did not work for 
me.

Source: 
http://stackoverflow.com/questions/14290113/git-pushing-code-to-two-remotes
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] subprocess.Popen(..., cwd) and UNC paths

2015-05-01 Thread Albert-Jan Roskam via Tutor


On Thu, Apr 30, 2015 1:12 AM CEST eryksun wrote:

>On Wed, Apr 29, 2015 at 11:54 AM, Albert-Jan Roskam
> wrote:
>> Hmmm, that sounds pretty convincing indeed (makes it even stranger that CD 
>> works the way it works).
>> I believe it threw a WindowsError, indicating that the file(s) could not be 
>> found, because the dir was
>> not changed. I actually first ran into this problem with this script, so 
>> with my current script I
>> immediately refrained from using cwd:
>> http://code.activestate.com/recipes/578883-git-pre-commit-hook-to-reject-large-files-using-py/
>> Git gave a fatal error in windows and the pushd/popd fixed it.
>
>I don't see why you'd need shell=True. Windows supports UNC paths in
>the working directory, but the cmd.exe shell (being a crusty relic of
>the 1980s) 

"Crusty relic" LOL :-)

(However, on POSIX systems, unlike Windows, using shell=False requires
>`cmd` to be a list.) 

Ah, maybe that caused the confusion. I used a str for cmd because I found it 
more readable that way. I could do cmd.split().

BTW, there's no need to explicitly pass
>cwd=os.getcwd(). The default behavior is to inherit the working
>directory of the current process.

Ok, I'll try this. I remember I was messing with this (hence the 'verbose' 
parameter). So os.getcwd() == os.path.dirname(os.path.abspath(__file__)) here? 
(Sorry, I can't try this now, even though I have QPython on my phone)

Best wishes,
Albert-Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions (and initial responses) on using version control: Why cannot I push my single (master) branch to origin without an error occurring?

2015-05-01 Thread Albert-Jan Roskam via Tutor


On Fri, May 1, 2015 5:39 AM CEST boB Stepp wrote:

>I created my remote repository on, say my C-drive, with "git init".

Not with 'git init --bare'?

I usually prefer initializing a remote with a readme, so I can simply clone it 
and then populate it with files. No 'git init' and 'git remote add' needed.

This book is good: https://pragprog.com/book/pg_git/pragmatic-guide-to-git

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


Re: [Tutor] Questions (and initial responses) on using version control: Why cannot I push my single (master) branch to origin without an error occurring?

2015-05-02 Thread Albert-Jan Roskam via Tutor

-
On Sat, May 2, 2015 6:19 AM CEST boB Stepp wrote:

>On Fri, May 1, 2015 at 1:41 PM, Albert-Jan Roskam  wrote:
>>
>> 
>> On Fri, May 1, 2015 5:39 AM CEST boB Stepp wrote:
>>
>>I created my remote repository on, say my C-drive, with "git init".
>>
>> Not with 'git init --bare'?
>
>Should I have used the option --bare? I was following along with the
>book, "Pro Git", which is available free on-line via the Git website.

Check out this page: 
http://stackoverflow.com/questions/7861184/what-is-the-difference-between-git-init-and-git-init-bare

Isn't the error you mentioned before the same?

>> I usually prefer initializing a remote with a readme, so I can simply clone 
>> it and then populate it with files. No 'git init' and 'git remote add' 
>> needed.
>
>I'm not certain I am following you here. When you say you are
>"initializing a remote with a readme", have you first run "git init"
>or "git init --bare" in that directory? And I presume the readme is
>the typical readme file that most projects have? And then you go to
>your working directory and run your git clone command? And then as you
>generate files in your working directory, you push them to the remote?

Sorry, that probably only applies when you use a web service like Github, 
Bitbucket, or Gitbucket.


>> This book is good: https://pragprog.com/book/pg_git/pragmatic-guide-to-git
>>
>Thanks for the link. Just now ordered it.

Yeah, that book has a good TL;DR rating. It's not exhaustive, but the commands 
you use most of the time are covered. Like "how do I undo a commit", or "How do 
I create a tag". I have this book, plus a big fat Git book with just about 
everything in it.


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


Re: [Tutor] Object references and garbage collection confusion

2015-05-05 Thread Albert-Jan Roskam via Tutor

-
On Tue, May 5, 2015 8:00 PM CEST Steven D'Aprano wrote:

>On Tue, May 05, 2015 at 12:29:59AM -0400, Brandon D wrote:
>> Hello tutors,
>> 
>> I'm having trouble understanding, as well as visualizing, how object
>> references work in the following situation.  For demonstration purposes I
>> will keep it at the most rudimentary level:
>> 
>> x = 10
>> 
>> x = x ** x
>
>
>In the first case statement, Python creates the integer object 10, and 
>binds it to the name 'x'. From this instant onwards, x will resolve as 
>the int 10.
>
>When the second line executes, Python first evaluates the right hand 
>side 'x ** x'. To do this, it looks up the name 'x', which resolves to 
>10. It then evaluates 10**10, which creates the int 100, and 
>binds that to the name 'x'. From this instant, x now resolves as the new 
>value 100.
>
>Immediately afterwards, Python sees that the int 10 is no longer in use. 
>(Well, in principle -- in practice, things are more complicated.) Since 
>it is no longer in use, the garbage collector deletes the object, and 
>reclaims the memory.
>
>That, at least, is how it works in principle. In practice, Python may 
>keep a cache of small integers, so that they never get deleted. That 
>makes things a bit faster, at the cost of a tiny amount of extra memory. 
>But this will depend on the version and implementation of Python. For 
>example, some versions of Python cached integers 0 to 100, others -1 to 
>255, very old versions might not cache any at all. As a Python 
>programmer, you shouldn't care about this, it is purely an optimization 
>to speed up the language.
>
>
>> If my knowledge serves me correctly, Python destroys the value once
>> reassigned.  So, how does x = x +  1 work if it's destroyed before it can
>> be referenced?  The only solution I came up with is that the two operands
>> are evaluated before storing it in the variable,
>
>Correct. Let's say x = 10 again, just for simplicity.
>
>Python first evaluates the right hand side: it looks up 'x', which 
>resolves to 10. Then it generates the int 1, and adds them together, 
>giving 11. Then it binds 11 to the name 'x', which frees up the 
>reference to 10, and (in principle) 10 will be deleted.
>
>The right hand side of the equals sign is always fully evaluated before 
>any assignments are done. This is why we can swap two variables like 
>this:
>
>a = 1
>b = 2
>a, b = b, a
>
>The third line evaluates b (giving 2) and a (giving 1), and Python then 
>does the assignment:
>
>a, b = 2, 1
>
>which is equivalent to a=2, b=1, thus swapping the values.


It will probably only add confusion, but I thought it'd be nice to mention the 
weakref module: http://pymotw.com/2/weakref/ (the only thing I *might* ever use 
is WeakValueDictionary or WeakKeyDictionary)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Learn python - Step by Step

2015-05-10 Thread Albert-Jan Roskam via Tutor


On Sat, May 9, 2015 7:08 PM CEST boB Stepp wrote:

>On Sat, May 9, 2015 at 3:23 AM, acolta  wrote:
>>
>> Hi guys,
>>
>> I want to start coding in python. My background is Linux/Bash/Perl 
>> (begginner).
>> My appreciate if somebody will recommend books/tutorials + exercises to 
>> practice.
>
>This question comes up quite frequently. If you have not done so
>already, try searching the Tutor archives.
>
>If you have a good bookstore nearby that is likely to carry
>programming-related books, you might just want to do some browsing and
>then look at reviews online. My local Barnes & Noble (I'm in the USA.)
>always has a selection of Python books.
>
>And of course there are tons of online resources, including tutorials
>on Python's official site. As always, a search engine is your good
>friend. Also, Alan Gauld (Moderator for this list.) has a good one.
>Look for one of his emails; he always has a link to it in his
>signature area.
>
>I am learning myself, and, being old-fashioned (I suppose.), I tend to
>prefer hard-copy books. If you feel any degree of comfort writing Perl
>scripts and programming in general, then you might jump into something
>like Mark Summerfield's two book series, "Programming in Python 3, 2nd
>ed." 

That book is goood, and even if you use Python 2 it barely matters that 
it's about Python 3.


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


Re: [Tutor] reading lines from a list of files

2015-05-12 Thread Albert-Jan Roskam via Tutor

--
On Tue, May 12, 2015 8:48 AM CEST Peter Otten wrote:

>Alex Kleider wrote:
>
>> Is there a better (more 'Pythonic') way to do the following?
>> 
>>  for f_name in f_names:
>>  with open(f_name, 'r') as f:
>>  for line in f:
>
>There's the fileinput module
>
>
>
>but personally I prefer the way you show above.

It was not that long ago that I found out about the fileinput module, so I 
sometimes forget to use it. It is not specify the encoding of the files, is it? 
It'd be nice if one could specify a tuple of encodings, e.g. ('utf-8-sig', 
'latin1', 'cp1252'). 

input(files=None, inplace=0, backup='', bufsize=0, mode='r', openhook=None)
input([files[, inplace[, backup[, mode[, openhook])
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading lines from a list of files

2015-05-12 Thread Albert-Jan Roskam via Tutor

--
On Tue, May 12, 2015 9:54 PM CEST Peter Otten wrote:

>Albert-Jan Roskam wrote:
>
>> It was not that long ago that I found out about the fileinput module, so I
>> sometimes forget to use it. It is not specify the encoding of the files,
>> is it? It'd be nice if one could specify a tuple of encodings, e.g.
>> ('utf-8-sig', 'latin1', 'cp1252').
>> 
>> input(files=None, inplace=0, backup='', bufsize=0, mode='r',
>> openhook=None)
>> input([files[, inplace[, backup[, mode[, openhook])
>
>Whatever you plan to do with these encodings, it should be possible with a 
>custom openhook.

Hi Peter,

Sorry, I should have read the documentation better. I did not know about 
openhooks. There's one useful hook already:

fileinput.hook_encoded(encoding)
Returns a hook which opens each file with codecs.open(), using the given 
encoding to read the file.
Usage example: 
fi = fileinput.FileInput(openhook=fileinput.hook_encoded("iso-8859-1"))
Note With this hook, FileInput might return Unicode strings depending on the 
specified encoding.
New in version 2.5.

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


[Tutor] https://trinket.io

2015-05-21 Thread Albert-Jan Roskam via Tutor
Hi,

Wired.com features trinket.io [1] and I thought it'd be nice to share this 
here: https://trinket.io. Not sure whether I like this better than IPython 
Notebook, though.

Regards,
Albert-Jan

[1] http://www.wired.com/2015/05/running-python-browser-awesome-think
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] ls *.py[co] >> .hidden

2015-05-21 Thread Albert-Jan Roskam via Tutor
Hi,

I would like to hide .pyc and .pyo files because they are visually distracting. 
Is the aforementioned command the best way? [1]. 

I know Python 3 uses __pycache__ (much better!), but I also need Python 2. And 
not writing bytecode files altogether using 
what's-that-environment-var-called-again is not an option for me. I use Debian 
Linux (Jessie, since today, yaaayy!)

 
Regards,


Albert-Jan


[1] 
http://superuser.com/questions/200730/hiding-files-of-a-certain-extension-pyc-from-nautilus

 



~~

All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

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


Re: [Tutor] ls *.py[co] >> .hidden

2015-05-21 Thread Albert-Jan Roskam via Tutor


- Original Message -

> From: Steven D'Aprano 
> To: tutor@python.org
> Cc: 
> Sent: Thursday, May 21, 2015 6:11 PM
> Subject: Re: [Tutor] ls *.py[co] >> .hidden
> 
> On Thu, May 21, 2015 at 03:54:20PM +0100, Bod Soutar wrote:
> 
>>  ls *.pyc *.pso >> .hidden
>> 
>>  should work
> [...]
>>  As this adds specific results of ls you will need to schedule the
>>  command through cron to get it to automatically add new files
> 
> Yes, but that's the point isn't it? If Nautilus understands regular 
> expressions, then instead of listing every single .pyc file by name, 
> potentially thousands of them, you just need a single entry:
> 
> .*pyc
> 
> to hide *every* .pyc file. Or use .*py[co] for .pyc and .pyo files.
> 
> If Nautilus *doesn't* understand regular expressions, well, that's just 
> another example of why Gnome is not good enough for serious work.
> 
> This suggests that Nautilus doesn't accept wildcards:
> 
> http://ubuntuforums.org/showthread.php?t=1730696


You're right, I just tried it:


# does NOT work:

echo *.py[co] > .hidden

# works (but you need a cronjob):

ls *.py[co] > .hidden

I just created an alias for this:
alias hidepycs="ls *.py[co] > .hidden"


No idea whether there exists some sneaky way to make Nautilius understand 
regexes. I could make an enhancement request, but with Debian this would become 
effective like 15 years later :-)

regards,
Albert-Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ls *.py[co] >> .hidden

2015-05-21 Thread Albert-Jan Roskam via Tutor


- Original Message -

> From: Alan Gauld 
> To: tutor@python.org
> Cc: 
> Sent: Friday, May 22, 2015 1:44 AM
> Subject: Re: [Tutor] ls *.py[co] >> .hidden
> 
> On 21/05/15 17:57, Emile van Sebille wrote:
>>  On 5/21/2015 9:28 AM, Albert-Jan Roskam via Tutor wrote:
>>>  I just created an alias for this:
>>>  alias hidepycs="ls *.py[co] > .hidden"
>> 
>>  Close -- try
>> 
>>  alias ls='ls --hide=*.py[co]'
>> 
> 
> I thought we'd established that this was to
> control visibility in the File Manager GUI
> not the CLI? So an 'ls' flag isn't going to
> help there.


Yes, it was about the visibility in Nautilius. Much easier on the eye when the 
bytecode files are not visible. 

Also, I sometimes accidentally open a .pyc when I intend to open the 
corresponding .py.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


tutor@python.org

2015-06-12 Thread Albert-Jan Roskam via Tutor
>
> From: Laura Creighton 
>To: Michelle Meiduo Wu  
>Cc: l...@openend.se; "tutor@python.org"  
>Sent: Thursday, June 11, 2015 11:11 PM
>Subject: Re: [Tutor] Python&Pytest
> 
>
>In a message of Thu, 11 Jun 2015 09:25:25 -0400, Michelle Meiduo Wu writes:
>>Hi there,
>>I'm looking for a language to write test scripts for our application. I read 
>>some document and found Pytest can be used to write simpler code compared 
>>with using unittest in Python. Does anybody know what's other pros and cons 
>>of using these two for writing test scripts?
>>Thank you,Michelle
>
>It is very much a 'try it and see what you like' sort of thing.
>



Hmm, I think it is possible to give some pros and cons. I have no experience 
with PyTest.
While I usually use unittest (just out of habit), I think nose is much easier 
and powerful.


* Unittest
Pros:
part of the Standard library
powerful, flexible

Cons:
need to declare a class to define one or more test cases (not so readable)

no (easy) test runner


* Doctest
Pros:
part of the Standard library
testable documentation


Cons:
Should be used for (testable) documentation, and nothing else
Basic use: easy. More advanced use: hard or impossible
No good for Python 2 & 3 code.


* Nose
Pros:
tests are readable; they are simply functions
generator tests
test runner for just about any other test module


cons:
not part of the Standard library
all tests pass in Python optimized mode (-O or -OO) --> because asserts are 
used!


* Pytest
???

* Dedicated test modules: numpy.testing, PyQt4.QtTest, etc.
Use whenever possible?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor