Skip to main content

Posts

Showing posts with the label python3

Go enjoy Python3

Given a string, get a truncated string of length up to 12. The task is ambiguous, as it doesn't say anything about whether or not 12 should include terminating null character or not. None the less, let's see how one would achieve this in various languages. Let's start with python3 import sys print(sys.argv[1][:12]) Simple enough, in essence given first argument, print it up to length 12. As an added this also deals with unicode correctly that is if passed arg is 車賈滑豈更串句龜龜契金喇車賈滑豈更串句龜龜契金喇, it will correctly print 車賈滑豈更串句龜龜契金喇. (note these are just random Unicode strings to me, no idea what they stand for). In C things are slightly more verbose, but in essence, I am going to use strncpy function: #include <stdio.h> #include <string.h> void main(int argc, char *argv[]) { char res[12]; strncpy(res,argv[1],12); printf("%s\n",res); } This treats things as byte-array instead of unicode, thus for unicode test it will end up printing just 車賈滑...

Python 3 ports of launchpadlib & ubuntu-dev-tools (library) are available

I'm happy to announce that Python 3 ports of launchpadlib & ubuntu-dev-tools (library) are available for consumption. These are 1.10.3 & 0.155 respectfully. This means that everyone should start porting their reports, tools, and scriptage to python3. ubuntu-dev-tools has the library portion ported to python3, as I did not dare to switch individual scripts to python3 without thorough interactive testing. Please help out porting those and/or file bug reports against the python3 port. Feel free to subscribe me to the bug reports on launchpad. For the time being, I believe some things will not be easy to port to python3 because of the elephant in the room - bzrlib. For some things like lp-shell, it should be easy to move away from bzrlib, as non-vcs things are used there. For other things the current suggestion is to probably fork to bzr binary or a python2 process. I ponder if a minimal usable python3-bzrlib wrapper around python2 bzrlib is possible to satisfy the nee...

Hacking on launchpadlib

So here is a quick sample of my progress playing around with launchpadlib using lp-shell from lptools: In [1]: lp Out[1]: <launchpadlib.launchpad.Launchpad at 0x7f49ecc649b0> In [2]: lp.distributions Out[2]: <launchpadlib.launchpad.DistributionSet at 0x7f49ddf0e630> In [3]: lp.distributions['ubuntu'] Out[3]: <distribution at https://api.launchpad.net/1.0/ubuntu> In [4]: lp.distributions['ubuntu'].display_name Out[4]: 'Ubuntu' In [5]: lp.distributions['ubuntu'].summary Out[5]: 'Ubuntu is a complete Linux-based operating system, freely available with both community and professional support.' In [7]: import sys; print(sys.version) 3.4.1 (default, Jun 9 2014, 17:34:49) [GCC 4.8.3] There is not much yet, but it's a start. python3 port of launchpadlib is coming soon. It has been attempted a few times before and I am leveraging that work. Porting this stack has proven to be the most difficult python3 port I have ever don...