News for hackers. Stuff that matters.
Re:Python 3.4 Beta 1 Released by taylorfausak on Sunday November 24, 2013 @08:14PM (#6791990)
Wow, I haven't heard of pathlib [1] before now, but it looks awesome! In particular, using the slash operator to join paths is brilliant.

    >>> p = PurePath('/etc')
    >>> p / 'init.d' / 'apache2'
    PurePosixPath('/etc/init.d/apache2')
[1]: http://docs.python.org/3.4/library/pathlib.html
Re:Python 3.4 Beta 1 Released by yareally on Sunday November 24, 2013 @09:33PM (#6792209)
Scala does something similarly neat with using #| for piping system commands.

Slash for Scala is not used by default though for path joining, but it can be by adding an implicit function:

  implicit def slash(str: String) = new { def /(joinStr: String) = str + java.io.File.separatorChar + joinStr} 

  val joinedStr = "abc"/"def"/"ghi"
  > joinedStr : java.lang.String = abc/def/ghi
Shell friendly syntax can be used for stdin/stdout in Scala as well (already in the stdlib with no implicits required):

#< Redirect STDIN

#> Redirect STDOUT

#>> Append to STDOUT

#&& Create an AND list

#!! Create an OR list

http://stackoverflow.com/questions/12772605/scala-shell-comm...

http://alvinalexander.com/scala/scala-execute-exec-external-...

Re:Python 3.4 Beta 1 Released by d0mine on Sunday November 24, 2013 @10:17PM (#6792316)
There are Plumbum shell combinators in Python http://plumbum.readthedocs.org/en/latest/
Re:Python 3.4 Beta 1 Released by voltagex_ on Monday November 25, 2013 @12:42AM (#6792708)
There are a couple of modules that do this kind of thing but Plumbum looks interesting, particularly

http://plumbum.readthedocs.org/en/latest/local_commands.html...

>from plumbum.cmd import cat

>>cat('tmp.txt') #invokes cat tmp.txt on the system

Re:Python 3.4 Beta 1 Released by thristian on Monday November 25, 2013 @04:58AM (#6793277)
I hadn't heard of it either, although I have played with Twisted's FilePath[1] class previously.

I didn't really understand the attraction of an OO filesystem API until I actually used it in anger and realised how handy it was that all the relevant functions were on the object I was messing with, instead of arbitrarily divided between the "os" and "os.path" modules.

Some (hopefully constructive) suggestions for the pathlib API:

- Python 3 dicts ditched .iterkeys(), .itervalues() and .iteritems(); why does pathlib use the clumsy .iterdir() when it could just be called .children?

- Like many Python programmers (I assume), I'm more familiar with POSIX command-line tools than I am with POSIX APIs. Command-line tools generally have an option to control whether they dereference symlinks (cp -L, find -L, etc) rather than having a separate. parallel tool that does the same thing. I think it would be neater if .lstat() and .lchmod() were removed in favour of a "follow_symlinks" parameter to .stat() and .chmod() (and .is_dir() and .touch() and .owner(), and, and, and..)

- If you're going to have convenience functions that pick out interesting bits from the .stat() return value, I would find .size() far more practical than .is_socket()

[1]: http://twistedmatrix.com/documents/current/api/twisted.pytho...

Re:Python 3.4 Beta 1 Released by yen223 on Sunday November 24, 2013 @09:50PM (#6792254)
One of the many things I like about Python is their pragmatic approach to operator overloading. Well, their pragmatic approach to everything, really.
Re:Python 3.4 Beta 1 Released by bodyfour on Sunday November 24, 2013 @09:32PM (#6792206)
FWIW, the boost::filesystem C++ package uses the / operator in the same way
Re:Python 3.4 Beta 1 Released by avdd_ on Sunday November 24, 2013 @11:25PM (#6792477)
No one objected to using "pure" instead of the more common "abstract" (which is the actual antonym of "concrete") ?? Why do people do this?
Re:Python 3.4 Beta 1 Released by CUViper on Monday November 25, 2013 @04:19AM (#6793185)
Concrete paths inherit from pure paths - this would be quite strange using antonyms. This isn't like an "abstract" base class. It's a full class on its own, which is extended by another.

Anyway, I think it's meant to be "pure" like pure functions, generally having no side effects or external inputs.

https://en.wikipedia.org/wiki/Pure_function

Re:Python 3.4 Beta 1 Released by quesebifurcan on Monday November 25, 2013 @05:41AM (#6793382)
i think so too. like it says in the docs: "Regardless of the system you’re running on, you can instantiate all of these classes, since they don’t provide any operation that does system calls." http://docs.python.org/3.4/library/pathlib.html#pure-paths
Re:Python 3.4 Beta 1 Released by reinhardt on Monday November 25, 2013 @03:03AM (#6792990)
The precursor path library [1] by J. Orendorff had the slash operator overloading trick a decade (or more) ago.

[1] https://pypi.python.org/pypi/path.py/1.2

Re:Python 3.4 Beta 1 Released by Flimm on Monday November 25, 2013 @07:27AM (#6793681)
I thought operator overloading like that was considered bad practise. It seems to me that the + operator should have been overloaded, not the / operator.