Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public I just need to print first element of tuple not the whole -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On 23/01/2014 07:37, lgabiot wrote:
Thanks to all,
that was indeed the tuple issue!
the correct code is:
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_levelhttps://wiki.python.org/moin/TupleSyntax
best regards.
No, you need to remember how to type xyz into your favourite search
engine. For this case xyz would be something like "python single
element tuple".
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
--
https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
On 22.01.2014 19:26, Chris Angelico wrote: > Internally, I believe CPython uses the GNU Multiprecision Library > (GMP), which gives an efficient representation and operation format, > scaling to infinity or thereabouts. You can go to any size of integer > you like without there being any difference. There's a cost to that > (even small integers are a bit slower to work with), but it's SO > helpful to be able to work with arbitrarily large numbers that it's > worth that cost. Small correction: Python isn't using GMP. Python uses its own implementation. -- https://mail.python.org/mailman/listinfo/python-list
Re: awesome slugify and unicode
On 23/01/2014 07:18, [email protected] wrote: Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a écrit : I thought this blog might interest some of you http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. This is not "unicode", only string manipulations. The same work could be done with, let say, cp1252. The difference lies in the repertoires of characters to be handled. A better way is to work with normalization() and/or with methods like .translate() with dedicated tables; the hard task being the creation of these tables. Shortly, very naive. jmf You'll have to excuse my ignorance of this stuff. How do I express the following in cp1252? def test_musical_notes(): txt = "Is ♬ ♫ ♪ ♩ a melody or just noise?" assert slugify(txt) == "Is-a-melody-or-just-noise" assert slugify_unicode(txt) == "Is-a-melody-or-just-noise" -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
On Thu, Jan 23, 2014 at 8:14 PM, Christian Heimes wrote: > On 22.01.2014 19:26, Chris Angelico wrote: >> Internally, I believe CPython uses the GNU Multiprecision Library >> (GMP), which gives an efficient representation and operation format, >> scaling to infinity or thereabouts. You can go to any size of integer >> you like without there being any difference. There's a cost to that >> (even small integers are a bit slower to work with), but it's SO >> helpful to be able to work with arbitrarily large numbers that it's >> worth that cost. > > Small correction: Python isn't using GMP. Python uses its own > implementation. Okay, wasn't sure. I've seen others that use GMP (including Pike, which can also use arbitrary-precision floats if you wish). Wrong in the specifics, right in the concept. Thanks for the correction. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
Le 23/01/14 10:04, Mark Lawrence a écrit : No, you need to remember how to type xyz into your favourite search engine. For this case xyz would be something like "python single element tuple". No big deal, but I don't think you are correct. Problem was that for me I "knew" (it was erroneous of course) that (element) was a python single element tuple... so there was no need for me to look for something I "knew". Once I understood that what I "knew" was wrong (that is after reading the answers to my first post), I did type xyz in my favourite search engine, which led me to the link I posted in my answer... -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Thursday, January 23, 2014 9:57:02 AM UTC+2, indar kumar wrote:
> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote:
> I just need to print first element of tuple not the whole
in hierarchies do steps level by level, that will make things much easier:
hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2':
('02:02:02:02:02:02', 1390461798.531)}],
'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2':
('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01',
1390461787.78)}]}
print(hosts['PC2'])
print(hosts['PC2'][3])
print(hosts['PC2'][3]['192.168.0.2'])
print(hosts['PC2'][3]['192.168.0.2'][1])
--
https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Thank You I have found this forum very helping...GOD BLESS YOU ALL -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thursday, January 23, 2014 3:15:07 PM UTC+5:30, lgabiot wrote: > Le 23/01/14 10:04, Mark Lawrence a écrit : > > No, you need to remember how to type xyz into your favourite search > > engine. For this case xyz would be something like "python single > > element tuple". > No big deal, but I don't think you are correct. > Problem was that for me I "knew" (it was erroneous of course) that > (element) was a python single element tuple... so there was no need for > me to look for something I "knew". > Once I understood that what I "knew" was wrong (that is after reading > the answers to my first post), I did type xyz in my favourite search > engine, which led me to the link I posted in my answer... Singleton tuples are a common gotcha in python Follows from the world-wide shortage in parenthesis -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On 1/23/2014 12:35 AM, Rustom Mody wrote:
On Thursday, January 23, 2014 10:11:42 AM UTC+5:30, Chris Angelico wrote:
I think it's fairly clear from the example that it has to be either a
tuple or a dict. Looks fine to me.
yes 'from the example' and only from there!
'parameters' is a single parameter, which could be called 'seq_dict'.
Let(seq_dict) must equal the number of replacements. A dict with extra
pairs raises.
A list instead of a tuple does work, but not an iterable, so 'sequence'.
A dict subclass works, but a UserDict is treated as a sequence.
---
import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table people (name_last, age)")
who = "Yeltsin"
age = 72
s = (who, age)
d = {'who':who, 'age':age}
class D(dict): pass
dD = D(d)
from collections import UserDict
dU = UserDict(d)
# This is the qmark style:
cur.execute("insert into people values (?, ?)", s)
# And this is the named style:
cur.execute("select * from people where name_last=:who and age=:age", dU)
print(cur.fetchone())
--
>>>
Traceback (most recent call last):
File "C:\Programs\Python34\tem.py", line 23, in
cur.execute("select * from people where name_last=:who and
age=:age", dU)
File "C:\Programs\Python34\lib\collections\__init__.py", line 883, in
__getitem__
raise KeyError(key)
KeyError: 0
Replacing dU in the last call with s works!
http://bugs.python.org/issue20364
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Re: awesome slugify and unicode
Le jeudi 23 janvier 2014 10:14:48 UTC+1, Mark Lawrence a écrit : > On 23/01/2014 07:18, [email protected] wrote: > > > Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a écrit : > > >> I thought this blog might interest some of you > > >> > > >> http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html > > >> > > >> My fellow Pythonistas, ask not what our language can do for you, ask > > >> > > >> what you can do for our language. > > >> > > > > > > This is not "unicode", only string manipulations. > > > The same work could be done with, let say, cp1252. > > > The difference lies in the repertoires of characters > > > to be handled. > > > > > > A better way is to work with normalization() and/or > > > with methods like .translate() with dedicated > > > tables; the hard task being the creation of these tables. > > > > > > Shortly, very naive. > > > > > > jmf > > > > > > > You'll have to excuse my ignorance of this stuff. How do I express the > > following in cp1252? > > > > def test_musical_notes(): > > txt = "Is ♬ ♫ ♪ ♩ a melody or just noise?" > > assert slugify(txt) == "Is-a-melody-or-just-noise" > > assert slugify_unicode(txt) == "Is-a-melody-or-just-noise" > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > I wrote: The same work could be done with, let say, cp1252. Understand: The same work (string manipulation) ... Would something like this not be more informative? >>> "Is ♬ ♫ ♪ ♩ a melody or just noise?".encode('ascii', >>> 'replace').decode('ascii') 'Is ? ? ? ? a melody or just noise?' >>> >>> cp1252 analogy. >>> 'abc€€€'.encode('cp1252').decode('ascii', 'replace').encode('ascii', >>> 'replace').decode('ascii') 'abc???' >>> Again, not a "unicode" question, more "how to handle strings in a judicious way?" jmf -- https://mail.python.org/mailman/listinfo/python-list
Re: awesome slugify and unicode
On Thu, Jan 23, 2014 at 9:41 PM, wrote:
"Is ♬ ♫ ♪ ♩ a melody or just noise?".encode('ascii',
'replace').decode('ascii')
> 'Is ? ? ? ? a melody or just noise?'
>
> cp1252 analogy.
>
'abc€€€'.encode('cp1252').decode('ascii', 'replace').encode('ascii',
'replace').decode('ascii')
> 'abc???'
>
> Again, not a "unicode" question, more "how to handle strings in a judicious
> way?"
I don't want a cp1252 analogy, I want the exact same thing implemented
in cp1252. You said the same work could be done there. That work
includes dealing with musical notes. How are you going to do that?
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: any wheel experts here?
On Wed, Jan 22, 2014 at 06:17:33AM -0800, Rustom Mody wrote: > On Wednesday, January 22, 2014 4:31:32 PM UTC+5:30, Oscar Benjamin wrote: > > Sounds reasonable. I don't know the answer or whether anyone else on this > > list > > will but you can definitely find the relevant developers at this mailing > > list: > > https://mail.python.org/mailman/listinfo/distutils-sig/ > > I believe the wheel/pip/virtualenv guys are on this list > > https://groups.google.com/forum/#!forum/python-virtualenv Maybe in some kind of quantum superposition they can be on both mailing lists at once! Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Wed, 22 Jan 2014 17:58:19 -0700, Larry Martell wrote: > I have the need to check for a files existence against a string, but I > need to do case-insensitively. Reading on, I see that your database assumes case-insensitive file names, while your file system is case-sensitive. Suggestions: (1) Move the files onto a case-insensitive file system. Samba, I believe, can duplicate the case-insensitive behaviour of NTFS even on ext3 or ext4 file systems. (To be pedantic, NTFS can also optionally be case- sensitive, although that it rarely used.) So if you stick the files on a samba file share set to case-insensitivity, samba will behave the way you want. (Although os.path.exists won't, you'll have to use nt.path.exists instead.) (2) Normalize the database and the files. Do a one-off run through the files on disk, lowercasing the file names, followed by a one-off run through the database, doing the same. (Watch out for ambiguous names like "Foo" and "FOO".) Then you just need to ensure new files are always named in lowercase. Also, keep in mind that just because os.path.exists reports a file exists *right now*, doesn't mean it will still exist a millisecond later when you go to use it. Consider avoiding os.path.exists altogether, and just trying to open the file. (Although I see you still have the problem that you don't know *which* directory the file will be found in. > I cannot efficiently get the name of > every file in the dir and compare each with my string using lower(), as > I have 100's of strings to check for, each in a different dir, and each > dir can have 100's of files in it. Does anyone know of an efficient way > to do this? There's no switch for os.path that makes exists() check > case-insensitively is there? Try nt.path.exists, although I'm not certain it will do what you want since it probably assumes the file system is case-insensitive. It really sounds like you have a hard problem to solve here. I strongly recommend that you change the problem, by renaming the files, or at least moving them into a consistent location, rather than have to repeatedly search multiple directories. Good luck! -- Steven -- https://mail.python.org/mailman/listinfo/python-list
SQLite + FTS (full text search)
Hi,
On my Debian stable 64-bit system, SQLite3 has FTS (full text search) enabled
(although at version 3 rather than the recommended version 4):
Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import sqlite3
>>> con = sqlite3.connect(":memory:")
>>> cur = con.execute("pragma compile_options")
>>> for row in cur:
print(row)
...
('ENABLE_FTS3',)
...
But on Windows when I use the official Python 3.3 32-bit binary from
www.python.org this is not enabled.
My guess is that on Debian, the packagers install a full SQLite 3 and the
Python package uses that. But on Windows I think the Python packagers bundle
their own SQLite (quite rightly since it might not already be installed).
I'd like the Windows binary to include SQLite 3 with FTS4 support, but I don't
know how much work that involves or if it would make the Python .msi file too
big?
Anyway, I guess if anyone else is interested in this they could perhaps reply
to indicate this?
If you're curious about the feature, it is documented here:
http://www.sqlite.org/fts3.html
--
https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
On Thursday, January 23, 2014 3:22:52 AM UTC+8, lgabiot wrote: > Le 22/01/14 18:31, 8 Dihedral a écrit : > > > > > > > > Check the C source code generated > > > by Pyrex and check cython for what u > > > want, but I did try that out in any > > > mobile phone or flat panel > > > programming. > > > > > > > Thanks a lot for your answer. > > > > I didn't use Pyrex or other tool, but wrote myself the C python > > wrapping, using the Python C/API documentation > > (http://docs.python.org/2/c-api/). I then used the distutils tool (via a > > setup.py file) to build my extension. > > While there is several function in my C code, only one needed to be > > accessed by python. > > > > I'll check Cython then, but is there any tweaking of the setup.py file > > using distutils that will help me compile the extension with the cairo > > lib embedded into it? There are some design concerns in writing python scripts that might be modified for fast execution speeds in some platforms. Well, reducing basic operation overheads in well factored critical parts does help in getting the desired results faster. -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On 2014-01-23 05:43, Terry Reedy wrote: > A list instead of a tuple does work, but not an iterable, so > 'sequence'. In the OP's case using sqlite drivers, this is true. However, I maintain some old 2.4 code that uses a correspondingly ancient version of mx.ODBC which requires a tuple and raises an exception on any other iterable. So I always use a tuple out of habit, even if it would be easier to just use some other iterable. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On 2014-01-22 17:58, Larry Martell wrote: > I have the need to check for a files existence against a string, > but I need to do case-insensitively. I cannot efficiently get the > name of every file in the dir and compare each with my string using > lower(), as I have 100's of strings to check for, each in a > different dir, and each dir can have 100's of files in it. Does > anyone know of an efficient way to do this? There's no switch for > os.path that makes exists() check case-insensitively is there? Is it possible to rephrase the problem in terms of a different algorithm that can be made case-insensitive? Something like from_db = set( row[0].upper() for row in db.execute( "select filename from tblfoo where ..." ).fetchall() ) from_fs = dict( (fname.upper(), os.path.join(pth, fname)) for pth, dirs, files in os.walk(ROOT) for fname in files ) common_filenames = from_db & set(from_fs) for fname in common_filenames: print from_fs[fname] -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: awesome slugify and unicode
On 23/01/2014 10:41, [email protected] wrote: Le jeudi 23 janvier 2014 10:14:48 UTC+1, Mark Lawrence a écrit : On 23/01/2014 07:18, [email protected] wrote: Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a écrit : I thought this blog might interest some of you http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. This is not "unicode", only string manipulations. The same work could be done with, let say, cp1252. The difference lies in the repertoires of characters to be handled. A better way is to work with normalization() and/or with methods like .translate() with dedicated tables; the hard task being the creation of these tables. Shortly, very naive. jmf You'll have to excuse my ignorance of this stuff. How do I express the following in cp1252? def test_musical_notes(): txt = "Is ♬ ♫ ♪ ♩ a melody or just noise?" assert slugify(txt) == "Is-a-melody-or-just-noise" assert slugify_unicode(txt) == "Is-a-melody-or-just-noise" -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. I wrote: The same work could be done with, let say, cp1252. Understand: The same work (string manipulation) ... Would something like this not be more informative? "Is ♬ ♫ ♪ ♩ a melody or just noise?".encode('ascii', 'replace').decode('ascii') 'Is ? ? ? ? a melody or just noise?' cp1252 analogy. 'abc€€€'.encode('cp1252').decode('ascii', 'replace').encode('ascii', 'replace').decode('ascii') 'abc???' Again, not a "unicode" question, more "how to handle strings in a judicious way?" jmf Now I'm really confused. I thought that the musical notes I've shown above are represented as unicode characters. So I'd like to see how you jmf would represent them in cp1252. Instead you give me an example showing a simple string manipulation which simply strips the characters that I want to see, then an even simpler example, clearly not what I've asked for. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
RE: SQLite + FTS (full text search)
> But on Windows when I use the official Python 3.3 32-bit binary from
> www.python.org this is not enabled.
For an unobtrusive way [1] to gain this, see apsw. For what it's worth, I prefer
this package over the built in module.
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit
(AMD64)]
...
IPython 2.0.0-dev -- An enhanced Interactive Python.
...
In [1]: import apsw
In [2]: c = apsw.Connection(':memory:')
In [3]: for x in c.cursor().execute('pragma compile_options'): print(x)
('ENABLE_FTS3',)
('ENABLE_FTS3_PARENTHESIS',)
('ENABLE_FTS4',)
('ENABLE_RTREE',)
('THREADSAFE=1',)
hth,
jlc
[1] See the sqlite mailing list for a way to replace the dll, while I have done
it I
also have tested it thoroughly.
--
https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
On Thursday, January 23, 2014 2:20:31 PM UTC+2, Mark Summerfield wrote:
> Hi,
> On my Debian stable 64-bit system, SQLite3 has FTS (full text search)
> enabled (although at version 3 rather than the recommended version 4):
>
> Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2
> Type "copyright", "credits" or "license()" for more information.
> >>> import sqlite3
> >>> con = sqlite3.connect(":memory:")
> >>> cur = con.execute("pragma compile_options")
> >>> for row in cur:
> print(row)
> ...
> ('ENABLE_FTS3',)
> ...
> But on Windows when I use the official Python 3.3 32-bit binary
> from www.python.org this is not enabled.
>
> My guess is that on Debian, the packagers install a full SQLite 3
> and the Python package uses that. But on Windows I think the Python
> packagers bundle their own SQLite (quite rightly since it might not
> already be installed).
>
> I'd like the Windows binary to include SQLite 3 with FTS4 support,
> but I don't know how much work that involves or if it would make
> the Python .msi file too big?
>
> Anyway, I guess if anyone else is interested in this they
> could perhaps reply to indicate this?
> If you're curious about the feature, it is documented here:
>
> http://www.sqlite.org/fts3.html
It is compile time option.
http://www.sqlite.org/compile.html#enable_fts3
you have to build it with this option enabled.
--
https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. I'm not sure, if this is the whole truth. think about this example: cat bla.py a = 10 cat foo.py from bla import a def stuff(): return a cat bar.py from foo import stuff print stuff() a = 5 print stuff() from bla import * print a python bar.py 10 10 10 here the a is coming from bla and is known in the global namespace. But the value differs in stuff() and before/after the import statement. So the instance of the module differs -> it cannot be a singelton. bg, Johannes -- Johannes Schneider Webentwicklung [email protected] Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
On 23/01/2014 13:24, Asaf Las wrote:
On Thursday, January 23, 2014 2:20:31 PM UTC+2, Mark Summerfield wrote:
Hi,
On my Debian stable 64-bit system, SQLite3 has FTS (full text search)
enabled (although at version 3 rather than the recommended version 4):
Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2
Type "copyright", "credits" or "license()" for more information.
import sqlite3
con = sqlite3.connect(":memory:")
cur = con.execute("pragma compile_options")
for row in cur:
print(row)
...
('ENABLE_FTS3',)
...
But on Windows when I use the official Python 3.3 32-bit binary
from www.python.org this is not enabled.
My guess is that on Debian, the packagers install a full SQLite 3
and the Python package uses that. But on Windows I think the Python
packagers bundle their own SQLite (quite rightly since it might not
already be installed).
I'd like the Windows binary to include SQLite 3 with FTS4 support,
but I don't know how much work that involves or if it would make
the Python .msi file too big?
Anyway, I guess if anyone else is interested in this they
could perhaps reply to indicate this?
If you're curious about the feature, it is documented here:
http://www.sqlite.org/fts3.html
It is compile time option.
http://www.sqlite.org/compile.html#enable_fts3
you have to build it with this option enabled.
As an option can be represented in a single bit then presumably the
Windows msi file only needs an extra bit to allow for this, or have I
missed something? While I'm at it what is this "compile time" thingy,
being on Windows I'm not used to seeing such terminology?
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
--
https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
On Thursday, January 23, 2014 3:39:08 PM UTC+2, Mark Lawrence wrote: > On 23/01/2014 13:24, Asaf Las wrote: > As an option can be represented in a single bit then presumably the > Windows msi file only needs an extra bit to allow for this, or have I > missed something? While I'm at it what is this "compile time" thingy, > being on Windows I'm not used to seeing such terminology? > Mark Lawrence Oh i am poor in terminology :-) from what i have seen in sqlite page i guess this option should included into list of defines for win ide or into compiler command line option or can be put directly onto header file as #define SQLITE_ENABLE_FTS3 to enable FTS am i wrong? -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
Hi, Mark Summerfield qtrac.plus.com> writes: > > My guess is that on Debian, the packagers install a full SQLite 3 and the Python package uses that. But on > Windows I think the Python packagers bundle their own SQLite (quite rightly since it might not already be installed). > > I'd like the Windows binary to include SQLite 3 with FTS4 support, but I don't know how much work that > involves or if it would make the Python .msi file too big? You can create a feature request on http://bugs.python.org Regards Antoine. -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
On Fri, Jan 24, 2014 at 12:39 AM, Mark Lawrence wrote: >> >> It is compile time option. >> http://www.sqlite.org/compile.html#enable_fts3 >> you have to build it with this option enabled. >> > > As an option can be represented in a single bit then presumably the Windows > msi file only needs an extra bit to allow for this, or have I missed > something? While I'm at it what is this "compile time" thingy, being on > Windows I'm not used to seeing such terminology? The implication of a compile-time switch is that it completely changes the code that gets compiled. For instance, Python 3.4 can be compiled with/out debugging support (which will slow down execution but enable certain features), with/out IPv6, and so on. Python 3.2 could also be compiled "narrow" or "wide" with regard to Unicode handling (internal representation UTF-16 or UTF-32). Each such change could make a huge difference to the size of the .msi file, but more importantly, a huge change to functionality. In the case of something like this, I'd guess that the compile-time switch would control the presence or absence of the code; at an absolute minimum, that would mean that disabling it makes for a smaller binary, but since it's an option I'd guess that there's more to it (maybe the presence of the feature has a performance penalty even if you don't use it). On Windows, where you're accustomed to downloading a ready-made binary, all compile-time choices were made for you at the time the binary was built. That's what compile time means - when Python (or SQLite) was turned from C source code into i386 or amd64 opcodes and packaged up into an exe and an msi. (In fact, one of the compile-time choices is the architecture - whether you build a 32-bit or 64-bit binary, whether you aim it at an Intel Itanium chip, etc, etc, etc. Generally, code runs only if the architecture is correct, though there are a few compatibility cases (i386 running on amd64, for instance).) The only real difference between Windows and Linux here is that it's customary for Linux systems to have C compilers readily available, where Windows generally forces you to think more about getting one. I can simply type "sudo apt-get build-dep python" on my Debian system and it'll go fetch a C compiler and all the necessary bits and bobs for building Python from source. (In fact, I did exactly that recently, as part of setting up a buildbot.) On Windows you would have to download the right compiler (probably some version of MS Visual Studio Express, if you want to replicate the python.org binaries), manually fetch any libraries you need, etc. It's more of a social difference than a technical one, but it does mean that your average Linux user is more likely to understand "Type ./configure --with-some-cool-feature to enable SomeCoolFeature" than your average Windows user is. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
datetime as subclass of date
This took my by surprise just now: >>> import datetime >>> now = datetime.datetime.now() >>> isinstance(now, datetime.datetime) True >>> isinstance(now, datetime.time) False >>> isinstance(now, datetime.date) True >>> issubclass(datetime.datetime, datetime.date) True I'd never paid any attention to the relationship between the datetime, time, and date classes of the datetime module before now, but have an application where, for backwards compatibility, date objects must be mapped to datetime objects with a time of midnight. That wasn't working, because I was asking if a datetime instance was an instance of a date. Which, it turns out, it is. Skip -- https://mail.python.org/mailman/listinfo/python-list
generate De Bruijn sequence memory and string vs lists
For reference, Wikipedia entry for De Bruijn sequence http://en.wikipedia.org/wiki/De_Bruijn_sequence At the above link is a python algorithm for generating De Brujin sequences. It works fine but outputs a list of integers [0, 0, 0, 1, 0, 1, 1, 1] and I would prefer a string '00010111'. This can be accomplished by changing the last line from; return sequence to return ''.join([str(i) for i in sequence]) See de_bruijn_1 Below. The other option would be to manipulate strings directly (kind of). I butchered the original algorithm to do this. See de_bruijn_2 below. But it is much slower and ungly. I am wanting to make a few large De Bruijin sequences. hopefully on the order of de_bruijn(4, 50) to de_bruijn(4, 100) (wishful thinking?). I don't know the limits (memory or time) for the current algorithms. I think I am will hit the memory mazsize limit at about 4^31. The system I will be using has 64GB RAM. The size of a De Brujin sequence is k^n My questions; 1, de_bruijn_2 is ugly, any suggestions to do it better? 2, de_bruijn_2 is significantly slower than de_bruijn_1. Speedups? 3, Any thought on which is more memory efficient during computation. 1 def de_bruijn_1(k, n): """ De Bruijn sequence for alphabet size k (0,1,2...k-1) and subsequences of length n. From wikipedia Sep 22 2013 """ a = [0] * k * n sequence = [] def db(t, p,): if t > n: if n % p == 0: for j in range(1, p + 1): sequence.append(a[j]) else: a[t] = a[t - p] db(t + 1, p) for j in range(int(a[t - p]) + 1, k): a[t] = j db(t + 1, t) db(1, 1) #return sequence #original return ''.join([str(i) for i in sequence]) d1 = de_bruijn_1(4, 8) 2 def de_bruijn_2(k, n): global sequence a = '0' * k * n sequence = '' def db(t, p): global sequence global a if t > n: if n % p == 0: for j in range(1, p + 1): sequence = sequence + a[j] else: a = a[:t] + a[t - p] + a[t+1:] db(t + 1, p) for j in range(int(a[t - p]) + 1, k): a = a[:t] + str(j) + a[t+1:] db(t + 1, t) return sequence db(1, 1) return sequence d2 = de_bruijn_2(4, 8) Vincent Davis -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
On Thursday, 23 January 2014 14:09:19 UTC, Antoine Pitrou wrote: > Hi, > > > > Mark Summerfield qtrac.plus.com> writes: > > > > > > My guess is that on Debian, the packagers install a full SQLite 3 and the > > Python package uses that. But on > > > Windows I think the Python packagers bundle their own SQLite (quite > > rightly since it might not already be installed). > > > > > > I'd like the Windows binary to include SQLite 3 with FTS4 support, but I > > don't know how much work that > > > involves or if it would make the Python .msi file too big? > > You can create a feature request on http://bugs.python.org > > Regards > > Antoine. Good point. I've now done that: http://bugs.python.org/issue20366 -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On 2014-01-23, Larry Martell wrote: > I have the need to check for a files existence against a string, but I > need to do case-insensitively. I cannot efficiently get the name of > every file in the dir and compare each with my string using lower(), > as I have 100's of strings to check for, each in a different dir, and > each dir can have 100's of files in it. Does anyone know of an > efficient way to do this? There's no switch for os.path that makes > exists() check case-insensitively is there? If you're on Unix, you could use os.popen() to run a find command using -iname. -- Grant Edwards grant.b.edwardsYow! I'm DESPONDENT ... I at hope there's something gmail.comDEEP-FRIED under this miniature DOMED STADIUM ... -- https://mail.python.org/mailman/listinfo/python-list
Initialise dictionary of dictionary
I need to initialise a dictionary of dictionary with float values. I do not know the size of the dictionary beforehand. How can we do that in Python -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thursday, January 23, 2014 4:13:26 PM UTC+5:30, Terry Reedy wrote:
> http://bugs.python.org/issue20364
Thanks for that!
I would have preferred a slightly louder warning with respect to singleton
tuples given that:
1. Singleton tuple syntax is not consistent with other-length tuples
2. This inconsistency is somewhat alleviated by the fact that in a classic
format ('%') expression, the second argument can be a single element when the
format string has only one %-spec -- so one inconsistency to correct another
3. conn.execute's parameters, apparently very analogous to the '%'
-- even more so given the standard sql-injection advisory -- is not consistent
with 2 above
Still the suggested doc-fix is much better than the current almost
undocumented situation -- so thanks again!
--
https://mail.python.org/mailman/listinfo/python-list
Re: Initialise dictionary of dictionary
On 2014-01-23 07:15, Ayushi Dalmia wrote:
> I need to initialise a dictionary of dictionary with float values.
> I do not know the size of the dictionary beforehand. How can we do
> that in Python --
Either
d = {}
or, if you want
from collections import defaultdict
d = defaultdict(float)
print(d["Hello"])
If you really do want a dict-of-dict that defaults to floats, you can
do
d = defaultdict(lambda: defaultdict(float))
print(d[3141]["Hello"])
-tkc
--
https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
On Thursday, January 23, 2014 7:09:08 PM UTC+5:30, Mark Lawrence wrote: > On 23/01/2014 13:24, Asaf Las wrote: > > It is compile time option. > > http://www.sqlite.org/compile.html#enable_fts3 > > you have to build it with this option enabled. > As an option can be represented in a single bit then presumably the > Windows msi file only needs an extra bit to allow for this, or have I > missed something? While I'm at it what is this "compile time" thingy, > being on Windows I'm not used to seeing such terminology? On intel processors, in the cr0 register there is a bit called the PE (protection enable) bit. Turn it off and you have 1M memory Turn it on and you will have GBs and more. A wee little bit more than a single bit dont you think? :D -- https://mail.python.org/mailman/listinfo/python-list
Re:Initialise dictionary of dictionary
Ayushi Dalmia Wrote in message: > I need to initialise a dictionary of dictionary with float values. I do not > know the size of the dictionary beforehand. How can we do that in Python > Do what? There's no concept of pre-initializing a dictionary, and there's no specific limit to its eventual size. Unsure of what the floats have to do with it. Perhaps you meant float KEYS. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Initialise dictionary of dictionary
On 2014-01-23 10:34, Dave Angel wrote: > Unsure of what the floats have to do with it. Perhaps you meant > float KEYS. using floats for keys can be dangerous, as small rounding errors in math can produce keys different enough that they're not found by an exact-match lookup. But yeah, the original problem specification was rather wanting in detail. I tried my best at interpreting it, for whatever that may be worth. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Wed, Jan 22, 2014 at 09:24:54PM -0700, Larry Martell wrote:
>
> I am writing something that is part of a django app, that based on
> some web entry from the user, I run a query, get back a list of files
> and have to go receive them and serve them up back to the browser. My
> script is all done and seem to be working, then today I was informed
> it was not serving up all the images. Debugging revealed that it was
> this case issue - I was matching with exists(). As I've said, coding a
> solution is easy, but I fear it will be too slow. Speed is important
> in web apps - users have high expectations. Guess I'll just have to
> try it and see.
How long does it actually take to serve a http request? I would expect it to
be orders of magnitudes slower than calling os.listdir on a directory
containing hundreds of files.
Here on my Linux system there are 2000+ files in /usr/bin. Calling os.listdir
takes 1.5 milliseconds (warm cache):
$ python -m timeit -s 'import os' 'os.listdir("/usr/bin")'
1000 loops, best of 3: 1.42 msec per loop
Converting those to upper case takes a further .5 milliseconds:
$ python -m timeit -s 'import os' 'map(str.upper, os.listdir("/usr/bin"))'
1000 loops, best of 3: 1.98 msec per loop
Checking a string against that list takes .05 milliseconds:
$ python -m timeit -s 'import os' \
'"WHICH" in map(str.upper, os.listdir("/usr/bin"))'
1000 loops, best of 3: 2.03 msec per loop
Oscar
--
https://mail.python.org/mailman/listinfo/python-list
Re:generate De Bruijn sequence memory and string vs lists
Vincent Davis Wrote in message: > (something about your message seems to make it unquotable) 64gig is 4^18, so you can forget about holding a string of size 4^50 If memory size is your issue, why not make the function a generator, by replacing the append with a yield? -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
Johannes Schneider Wrote in message: > On 22.01.2014 20:18, Ned Batchelder wrote: >> On 1/22/14 11:37 AM, Asaf Las wrote: >> Chris is right here, too: modules are themselves singletons, no matter >> how many times you import them, they are only executed once, and the >> same module object is provided for each import. > > I'm not sure, if this is the whole truth. > > think about this example: > > cat bla.py > a = 10 > > cat foo.py > from bla import a > > def stuff(): > return a > > cat bar.py > from foo import stuff > print stuff() > a = 5 > print stuff() > > from bla import * > print a > > python bar.py > 10 > 10 > 10 > > here the a is coming from bla and is known in the global namespace. But > the value differs in stuff() and before/after the import statement. So > the instance of the module differs -> it cannot be a singelton. > You're using 3 different variables here, each global to its own module. If you really want to access the same object, you need to reference it as bla.a. And ditch the from deal. A from x import y. statement produces a new binding to the same object. But since the object in your example is immutable, the only way it can seem to change is by rebinding. If several names are bound to the same object, rebinding one has no effect on the others. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On Thu, Jan 23, 2014 at 10:18 AM, Dave Angel wrote: > If memory size is your issue, why not make the function a > generator, by replacing the append with a yield? > One more thought on the generator. I have an idea for how to use the generator but I still need 1, chucks of size n de_brujin(k, n) and the ordering the same ordering as found in de_brujin(k, n). I am not really sure how to modify the algorithm to do that. Any ideas? I won't have time to think hard about that until later. Vincent Davis 720-301-3003 -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Vincent Davis wrote: > For reference, Wikipedia entry for De Bruijn sequence > http://en.wikipedia.org/wiki/De_Bruijn_sequence > > At the above link is a python algorithm for generating De Brujin > sequences. It works fine but outputs a list of integers [0, 0, 0, 1, 0, 1, > 1, 1] and I would prefer a string '00010111'. This can be accomplished by > changing the last line from; > return sequence > to > return ''.join([str(i) for i in sequence]) > See de_bruijn_1 Below. > > The other option would be to manipulate strings directly (kind of). > I butchered the original algorithm to do this. See de_bruijn_2 below. But > it is much slower and ungly. > > I am wanting to make a few large De Bruijin sequences. hopefully on the > order of de_bruijn(4, 50) to de_bruijn(4, 100) (wishful thinking?). I > don't know the limits (memory or time) for the current algorithms. I think > I am will hit the memory mazsize limit at about 4^31. The system I will be > using has 64GB RAM. > The size of a De Brujin sequence is k^n > > My questions; > 1, de_bruijn_2 is ugly, any suggestions to do it better? > 2, de_bruijn_2 is significantly slower than de_bruijn_1. Speedups? > 3, Any thought on which is more memory efficient during computation. > > 1 > def de_bruijn_1(k, n): > """ > De Bruijn sequence for alphabet size k (0,1,2...k-1) > and subsequences of length n. > From wikipedia Sep 22 2013 > """ > a = [0] * k * n > sequence = [] > def db(t, p,): > if t > n: > if n % p == 0: > for j in range(1, p + 1): > sequence.append(a[j]) > else: > a[t] = a[t - p] > db(t + 1, p) > for j in range(int(a[t - p]) + 1, k): > a[t] = j > db(t + 1, t) > db(1, 1) > #return sequence #original > return ''.join([str(i) for i in sequence]) > > d1 = de_bruijn_1(4, 8) > > 2 > def de_bruijn_2(k, n): > global sequence > a = '0' * k * n > sequence = '' > def db(t, p): > global sequence > global a > if t > n: > if n % p == 0: > for j in range(1, p + 1): > sequence = sequence + a[j] > else: > a = a[:t] + a[t - p] + a[t+1:] > db(t + 1, p) > for j in range(int(a[t - p]) + 1, k): > a = a[:t] + str(j) + a[t+1:] > db(t + 1, t) > return sequence > db(1, 1) > return sequence > > d2 = de_bruijn_2(4, 8) You could change de_bruijn_1() to use `bytearray`s instead of `list`s: # Python 2 def debruijn(k, n): a = k * n * bytearray([0]) sequence = bytearray() append = sequence.append # factor out method lookup def db(t, p,): if t > n: if n % p == 0: for j in xrange(1, p + 1): append(a[j]+48) # add 48 to convert to ascii else: a[t] = a[t - p] db(t + 1, p) for j in xrange(a[t - p] + 1, k): a[t] = j db(t + 1, t) db(1, 1) return sequence -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Peter Otten wrote: > You could change de_bruijn_1() to use `bytearray`s instead of `list`s: > > # Python 2 > def debruijn(k, n): > a = k * n * bytearray([0]) > sequence = bytearray() > append = sequence.append # factor out method lookup > def db(t, p,): > if t > n: > if n % p == 0: > for j in xrange(1, p + 1): > append(a[j]+48) # add 48 to convert to ascii > else: > a[t] = a[t - p] > db(t + 1, p) > for j in xrange(a[t - p] + 1, k): > a[t] = j > db(t + 1, t) > db(1, 1) > return sequence I just noted that the first Python loop can be eliminated: def debruijn(k, n): a = k * n * bytearray([0]) sequence = bytearray() extend = sequence.extend # factor out method lookup def db(t, p): if t > n: if n % p == 0: extend(a[1: p+1]) else: a[t] = a[t - p] db(t + 1, p) for j in xrange(a[t - p] + 1, k): a[t] = j db(t + 1, t) db(1, 1) return sequence.translate(_mapping) -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On 1/23/14, 10:18 AM, Dave Angel wrote: > (something about your message seems to make it unquotable) Not sure why the message was not quotable. I sent it using gmail. On 1/23/14, 10:18 AM, Dave Angel wrote: > 64gig is 4^18, so you can forget about holding a string of size 4^50 I guess I will have to buy more memory or be happy with less, 4**17 would be ok. On 1/23/14, 10:18 AM, Dave Angel wrote: > If memory size is your issue, why not make the function a > generator, by replacing the append with a yield? I plan to use the sequence as an index to count occurrences of sequences of length n. A generator is equivalent to using itertools.permutations (i think that the right itertool). My thought is that I don't have to store each individual (sub)sequence since the De Brujin sequence contains all of them. i.e. it is a compact representation of every sequence generated by itertools.permutations. Vincent Davis On Thu, Jan 23, 2014 at 10:18 AM, Dave Angel wrote: > > Vincent Davis Wrote in message: > > > (something about your message seems to make it unquotable) > > 64gig is 4^18, so you can forget about holding a string of size 4^50 > > If memory size is your issue, why not make the function a > generator, by replacing the append with a yield? > > > -- > DaveA > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Separate Address number and name
On Wed, 22 Jan 2014 17:35:22 +, Denis McMahon wrote: > On Tue, 21 Jan 2014 16:06:56 -0800, Shane Konings wrote: >> The following is a sample of the data. > A mechanism using regexes Just to follow up, using regexes I transformed the sample data that I believe is as follows: inputData = [ "1 1067 Niagara Stone Rd, W, Niagara-On-The-Lake, ON L0S 1J0", "2 4260 Mountainview Rd, Lincoln, ON L0R 1B2", "3 25 Hunter Rd, Grimsby, E, ON L3M 4A3", "4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0", "5 5172 Green Lane Rd, Lincoln, ON L0R 1B3", "6 500 Glenridge Ave, East, St. Catharines, ON L2S 3A1", "7 471 Foss Rd, Pelham, ON L0S 1C0", "8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0", "9 3836 Main St, North, Lincoln, ON L0R 1S0", "10 1025 York Rd, W, Niagara-On-The-Lake, ON L0S 1P0" ] Into the following: 1,1067,Niagara Stone,Rd,W,Niagara-On-The-Lake,ON,L0S 1J0 2,4260,Mountainview,Rd,,Lincoln,ON,L0R 1B2 3,25,Hunter,Rd,Grimsby,E,ON,L3M 4A3 4,1091,Hutchinson,Rd,,Haldimand,ON,N0A 1K0 5,5172,Green Lane,Rd,,Lincoln,ON,L0R 1B3 6,500,Glenridge,Ave,East,St. Catharines,ON,L2S 3A1 7,471,Foss,Rd,,Pelham,ON,L0S 1C0 8,758,Niagara Stone,Rd,,Niagara-On-The-Lake,ON,L0S 1J0 9,3836,Main,St,North,Lincoln,ON,L0R 1S0 10,1025,York,Rd,W,Niagara-On-The-Lake,ON,L0S 1P0 Which should then read into Excel as CSV just fine. One final question though, why are you using excel to manipulate data that looks as if it would be better held in and manipulated by a database? -- Denis McMahon, [email protected] -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Wed, Jan 22, 2014 at 9:29 PM, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:24 PM, Larry Martell > wrote: >> I am writing something that is part of a django app, that based on >> some web entry from the user, I run a query, get back a list of files >> and have to go receive them and serve them up back to the browser. My >> script is all done and seem to be working, then today I was informed >> it was not serving up all the images. Debugging revealed that it was >> this case issue - I was matching with exists(). As I've said, coding a >> solution is easy, but I fear it will be too slow. Speed is important >> in web apps - users have high expectations. Guess I'll just have to >> try it and see. > > Would it be a problem to rename all the files? Then you could simply > lower() the input name and it'll be correct. So it turned out that in the django model definition for this object there was code that was doing some character mapping that was causing this. That code was added to 'fix' another problem, but the mapping strings were not qualified enough and it was doing some unintended mapping. Changing those strings to be more specific fixed my problem. Thanks to all for the replies. -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On Thu, Jan 23, 2014 at 12:02 PM, Peter Otten <[email protected]> wrote: > > I just noted that the first Python loop can be eliminated: > > def debruijn(k, n): > a = k * n * bytearray([0]) > sequence = bytearray() > extend = sequence.extend # factor out method lookup > def db(t, p): > if t > n: > if n % p == 0: > extend(a[1: p+1]) > else: > a[t] = a[t - p] > db(t + 1, p) > for j in xrange(a[t - p] + 1, k): > a[t] = j > db(t + 1, t) > db(1, 1) > return sequence.translate(_mapping) I am not really sure what _mapping should be. The code above does not run because NameError: global name '_mapping' is not defined I tried to get the bytearray sequence to convert to ascii but don't know how to. Vincent Davis -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Vincent Davis wrote: > On Thu, Jan 23, 2014 at 12:02 PM, Peter Otten <[email protected]> wrote: >> >> I just noted that the first Python loop can be eliminated: Oops, I forgot to paste import string def chars(a, b): return "".join(map(chr, range(a, b))) _mapping = string.maketrans(chars(0, 10), chars(48, 58)) >> def debruijn(k, n): >> a = k * n * bytearray([0]) >> sequence = bytearray() >> extend = sequence.extend # factor out method lookup >> def db(t, p): >> if t > n: >> if n % p == 0: >> extend(a[1: p+1]) >> else: >> a[t] = a[t - p] >> db(t + 1, p) >> for j in xrange(a[t - p] + 1, k): >> a[t] = j >> db(t + 1, t) >> db(1, 1) >> return sequence.translate(_mapping) > > > I am not really sure what _mapping should be. The code above does not run > because > NameError: global name '_mapping' is not defined > I tried to get the bytearray > > sequence to convert to ascii but don't know how to. It does the same as adding 48 to every byte in the first variant: >>> import string >>> def chars(a, b): ... return "".join(map(chr, range(a, b))) ... >>> _mapping = string.maketrans(chars(0, 10), chars(48, 58)) >>> b = bytearray(range(10)) >>> b bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t') >>> b.translate(_mapping) bytearray(b'0123456789') The disadvantage of this approach is that it produces a new bytearray, i. e. it increases the peak amount of memory used by the function significantly. -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On 23/01/2014 20:10, Peter Otten wrote: Vincent Davis wrote: On Thu, Jan 23, 2014 at 12:02 PM, Peter Otten <[email protected]> wrote: I just noted that the first Python loop can be eliminated: Oops, I forgot to paste import string def chars(a, b): return "".join(map(chr, range(a, b))) _mapping = string.maketrans(chars(0, 10), chars(48, 58)) FTR string.maketrans is gone from Python 3.2+. Quoting from http://docs.python.org/dev/whatsnew/3.2.html#porting-to-python-3-2 "The previously deprecated string.maketrans() function has been removed in favor of the static methods bytes.maketrans() and bytearray.maketrans(). This change solves the confusion around which types were supported by the string module. Now, str, bytes, and bytearray each have their own maketrans and translate methods with intermediate translation tables of the appropriate type." -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On Thu, Jan 23, 2014 at 2:36 PM, Mark Lawrence wrote: > FTR string.maketrans is gone from Python 3.2+. Quoting from > http://docs.python.org/dev/whatsnew/3.2.html#porting-to-python-3-2 "The > previously deprecated string.maketrans() function has been removed in favor > of the static methods bytes.maketrans() and bytearray.maketrans(). This > change solves the confusion around which types were supported by the string > module. Now, str, bytes, and bytearray each have their own maketrans and > translate methods with intermediate translation tables of the appropriate > type." > Thanks for pointing this out Mark, I will soon be running this on 3.3+ Vincent Davis 720-301-3003 -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Vincent Davis wrote:
> On Thu, Jan 23, 2014 at 2:36 PM, Mark Lawrence
> wrote:
>
>> FTR string.maketrans is gone from Python 3.2+. Quoting from
>> http://docs.python.org/dev/whatsnew/3.2.html#porting-to-python-3-2 "The
>> previously deprecated string.maketrans() function has been removed in
>> favor of the static methods bytes.maketrans() and bytearray.maketrans().
>> This change solves the confusion around which types were supported by the
>> string module. Now, str, bytes, and bytearray each have their own
>> maketrans and translate methods with intermediate translation tables of
>> the appropriate type."
>>
>
> Thanks for pointing this out Mark, I will soon be running this on 3.3+
Well, my first post in this thread head this suspicious comment:
> # Python 2
> def debruijn(k, n):
In hindsight I have no idea what I was trying to say ;)
Anyway, as a special service to Mark and Vincent here's an updated version
that might work on both Python 2 and 3 (there's no test but the ad-hoc demo
in the if __name__ == "__main__" block):
[debruijn is Vincents original code, debruijn_bytes my modified version]
$ cat debruijn_compat.py
def debruijn(k, n):
"""
De Bruijn sequence for alphabet size k (0,1,2...k-1)
and subsequences of length n.
From wikipedia Sep 22 2013
"""
a = [0] * k * n
sequence = []
def db(t, p,):
if t > n:
if n % p == 0:
for j in range(1, p + 1):
sequence.append(a[j])
else:
a[t] = a[t - p]
db(t + 1, p)
for j in range(int(a[t - p]) + 1, k):
a[t] = j
db(t + 1, t)
db(1, 1)
return ''.join(map(str, sequence))
_mapping = bytearray(b"?")*256
_mapping[:10] = b"0123456789"
def debruijn_bytes(k, n):
a = k * n * bytearray([0])
sequence = bytearray()
extend = sequence.extend
def db(t, p):
if t > n:
if n % p == 0:
extend(a[1: p+1])
else:
a[t] = a[t - p]
db(t + 1, p)
for j in range(a[t - p] + 1, k):
a[t] = j
db(t + 1, t)
db(1, 1)
return sequence.translate(_mapping).decode("ascii")
if __name__ == "__main__":
d1 = debruijn(4, 8)
d2 = debruijn_bytes(4, 8)
print(d1[:50])
print(d2[:50])
assert d1 == d2
$ python debruijn_compat.py
1000200030011001200130
1000200030011001200130
$ python3 debruijn_compat.py
1000200030011001200130
1000200030011001200130
$ python -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, 8)'
10 loops, best of 3: 53.5 msec per loop
$ python -m timeit -s 'from debruijn_compat import debruijn_bytes as d'
'd(4, 8)'
10 loops, best of 3: 22.2 msec per loop
$ python3 -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, 8)'
10 loops, best of 3: 68 msec per loop
$ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d'
'd(4, 8)'
10 loops, best of 3: 21.7 msec per loop
--
https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote:
> Hi,
>
>
>
> I want to show a code for review but afraid of plagiarism issues. Kindly,
> suggest how can I post it for review here without masking it visible for
> public
hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2':
('02:02:02:02:02:02', 1390461798.531)}],'PC1':['01:01:01:01:01:01',
'192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531),
'192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}
Hi,
I want to print a value before a particular value inside of a list associated
with a key inside main dictionary(hosts) not the one inside nested dictionary.
Forexample,
I want the user to input ip e.g. 192.168.0.2 and then search through dictionary
print MAC e.g.02:02:02:02:02:02 that is just before that IP. Note that host
id(e.g.PC2) is not known user just inputs IP.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On 1/23/2014 1:15 PM, indar kumar wrote:
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote:
Hi,
I want to show a code for review but afraid of plagiarism issues. Kindly,
suggest how can I post it for review here without masking it visible for public
hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2':
('02:02:02:02:02:02', 1390461798.531)}],'PC1':['01:01:01:01:01:01',
'192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531),
'192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}
Hi,
I want to print a value before a particular value inside of a list associated
with a key inside main dictionary(hosts) not the one inside nested dictionary.
Forexample,
I want the user to input ip e.g. 192.168.0.2 and then search through dictionary
print MAC e.g.02:02:02:02:02:02 that is just before that IP. Note that host
id(e.g.PC2) is not known user just inputs IP.
Like this?:
>>> hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200',
... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],
...'PC1':['01:01:01:01:01:01', '192.168.0.1', '200',
... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531),
...'192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}
>>>
>>> searchfor = '192.168.0.1'
>>>
>>> print [ ii[0] for ii in hosts.values() if ii[1] == searchfor ]
['01:01:01:01:01:01']
--
https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Just the value e.g.01:01:01:01:01:01 not the list -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On 1/23/2014 1:34 PM, indar kumar wrote: On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: Hi, I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Just the value e.g.01:01:01:01:01:01 not the list It may be time for you to work your way through the tutorial. Emile -- https://mail.python.org/mailman/listinfo/python-list
The potential for a Python 2.8.
http://regebro.wordpress.com/2014/01/23/the-potential-for-a-python-2-8/ I pretty much agree with the author. In fact, the sooner this whole ludicrous idea of Python 2.8 has been buried under a massive avalanche or cremated in a sizeable volcano, then the better for the future of Python development. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Can I do the following to just get the value as string not the type list? searchfor = '192.168.0.2' z=[ii[0] for ii in hosts.values() if ii[1] == searchfor] >>> str1 = ''.join(z) >>> str1 -- https://mail.python.org/mailman/listinfo/python-list
Re: datetime as subclass of date
Skip Montanaro writes: > […] I was asking [Python] if a datetime instance was an instance of a > date. Which, it turns out, it is. Yep. Makes sense, since ‘datetime’ can do everything ‘date’ can do, and is conceptually a subset of the same concept. The same is not true of the ‘time’ type from that module, by the way; it does not represent a specific point on the timeline. So ‘datetime’ inheriting from ‘time’ wouldn't make sense. Just in case anyone was wondering. -- \ “There is something wonderful in seeing a wrong-headed majority | `\ assailed by truth.” —John Kenneth Galbraith, 1989-07-28 | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On Thu, Jan 23, 2014 at 3:15 PM, Peter Otten <[email protected]> wrote: > $ python -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, 8)' > 10 loops, best of 3: 53.5 msec per loop > $ python -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 8)' > 10 loops, best of 3: 22.2 msec per loop > $ python3 -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, > 8)' > 10 loops, best of 3: 68 msec per loop > $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 8)' > 10 loops, best of 3: 21.7 msec per loop > Excellent Peter! I have a question, the times reported don't make sense to me, for example $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' 'd(4, 8)' 100 loops, best of 3: 10.2 msec per loop This took ~4 secs (stop watch) which is much more that 10*.0102 Why is this? $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' 'd(4, 11)' 10 loops, best of 3: 480 msec per loop This took ~20 secs vs .480*10 d(4, 14) takes about 24 seconds (one run) Vincent Davis -- https://mail.python.org/mailman/listinfo/python-list
Dipy 0.7.1 is now available for download!
Dear all, We are very happy to announce another major release of Diffusion Imaging in Python (Dipy). http://dipy.org Here we list some of the major new features: *0.7.1 *(Thursday, 16 Jan 2014) *Reconstruction* * Constrained Spherical Deconvolution (CSD). * Simple Harmonic Oscillator based Reconstruction and Estimation (SHORE). * Sharpening Deconvolution Transform (SDT). * Signal-to-noise ratio estimation. * RESTORE fitting for DTI. * Westin's Tensor maps. *Tracking* * Enabled automated seeding in masks. * Streamline filtering through specific ROIs using `target`. *Segmentation* * Brain and foreground extraction using median_otsu. *Visualization* * Streamtube visualization. * Simultaneous peaks and ODF visualization. *Connectivity * * Connectivity matrices and density maps. *Parallel processing* * Parallel processing is possible for all reconstruction models using `peaks_from_model`. *Data access* * Access to more publicly available datasets directly through Dipy functions. *Installation* * Installing Dipy is now easier and more universal. * Available with pip, easy_install, neurodebian and other methods. http://dipy.org/installation.html *Overall* * 3x more tutorials than previous release. http://dipy.org/examples_index.html * 2x more contributors from the previous release. http://dipy.org/developers.html Yours sincerely, On behalf of all Dipy developers Eleftherios Garyfallidis -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
Johannes Schneider Wrote in message: On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. I'm not sure, if this is the whole truth. think about this example: cat bla.py a = 10 cat foo.py from bla import a This makes a a global in foo, bound to 10 def stuff(): return a This a refers to the global a in foo. cat bar.py from foo import stuff print stuff() a = 5 This bar.a is irrelevant to the behavior of stuff. print stuff() from bla import * print a python bar.py 10 foo.a == 10 10 foo.a == 10 10 bla.a == 10 here the a is coming from bla Twice and is known in the global namespace. There is no global namespace outside of modules. the value differs in stuff() No it does not. and before/after the import statement. foo.a does not change. bar.a is never used. So the instance of the module differs Nope. Each of the three module instances is constant. The bindings within each could change, but there are no rebinding in the code above. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: datetime as subclass of date
In article , Ben Finney wrote: > Skip Montanaro writes: > > > [â¦] I was asking [Python] if a datetime instance was an instance of a > > date. Which, it turns out, it is. > > Yep. Makes sense, since âdatetimeâ can do everything âdateâ can do, > and > is conceptually a subset of the same concept. That's reasonable, but given that, it's weird that date(2014, 1, 23) == datetime(2014, 1, 23) is False. You would think it should be True, in the same way that 1 + 0j == 1 is True. -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 1/23/2014 4:57 PM, Mark Lawrence wrote: http://regebro.wordpress.com/2014/01/23/the-potential-for-a-python-2-8/ I pretty much agree with the author. Except for one paragraph, which I consider a disservice to readers. "Does that mean a Python 2.8 can not happen? No, it can. If the Python "core developers decide that Python 3 was a dead end, then obviously a "Python 2.8 will happen. But that is a big if, and it certainly isn’t "going to happen anytime soon. This will never happen. Python 3 is the escape from several dead-ends in Python 2. The biggest in impact is the use of un-accented latin chars as text in a global, unicode world. "The other way it can happen if somebody forks Python 2, and makes a "Python 2.8. It will have to be released under another name, though, "but should “Psnakes 2.8″ become a big success, this may also change "the core developers minds. Not mine, and I am sure many if not all others. I believe Python 3 is already more successful than my first Python, 1.3, was. Python 3 is the bugfix for several design bugs in Python 1 and 2. The idea that we would we *ever* unfix those bugs is ludicrous. In fact, the sooner this whole ludicrous idea of Python 2.8 has been buried under a massive avalanche or cremated in a sizeable volcano, then the better for the future of Python development. Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. Developers informally said 'No 2.8'. People would not believe that. So developers formally said 'No 2.8'. They even inverted the purpose of PEP to make the formal announcement visible and permanent. And a few people still do not want to believe it. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite + FTS (full text search)
On 1/23/2014 8:24 AM, Asaf Las wrote:
On Thursday, January 23, 2014 2:20:31 PM UTC+2, Mark Summerfield wrote:
Hi,
On my Debian stable 64-bit system, SQLite3 has FTS (full text search)
enabled (although at version 3 rather than the recommended version 4):
Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2
Type "copyright", "credits" or "license()" for more information.
import sqlite3
con = sqlite3.connect(":memory:")
cur = con.execute("pragma compile_options")
for row in cur:
print(row)
...
('ENABLE_FTS3',)
...
But on Windows when I use the official Python 3.3 32-bit binary
from www.python.org this is not enabled.
On 64 bit 3.4.0b2, the output is ('THREADSAFE=1',)
My guess is that on Debian, the packagers install a full SQLite 3
and the Python package uses that. But on Windows I think the Python
packagers bundle their own SQLite (quite rightly since it might not
already be installed).
I'd like the Windows binary to include SQLite 3 with FTS4 support,
but I don't know how much work that involves or if it would make
the Python .msi file too big?
Anyway, I guess if anyone else is interested in this they
could perhaps reply to indicate this?
If you're curious about the feature, it is documented here:
http://www.sqlite.org/fts3.html
It is compile time option.
http://www.sqlite.org/compile.html#enable_fts3
you have to build it with this option enabled.
If one clones the hg.python.org/cpython repository and runs
Tools/buildbots/external.bat with minimal svn installed, it copies
sqlite3 source into sqlite-3.8.1 with files
shell.c
sqlite3.c # 5 mb
sqlite3.h
sqlite3ext.h
If that is everything needed for FTS and if pcbuild/ _sqlite3 and
sqlite3 project files were altered to change the compile option and
anything else needed ... then you would have FTS on Windows.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On Fri, Jan 24, 2014 at 11:42 AM, Terry Reedy wrote: > Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. > Developers informally said 'No 2.8'. People would not believe that. So > developers formally said 'No 2.8'. They even inverted the purpose of PEP to > make the formal announcement visible and permanent. And a few people still > do not want to believe it. Can I get a new version of Java 1.1.8 please? I want it to include all the cool features that I want from the newer versions, but it has to still run all my existing code. I'm not going to put in any effort to actually _make_ this, I want you to do it for me. Actually, the Java versioning system was enough of a mess that, to this day, I don't know what version(s) my old Java code would and wouldn't run on. So glad to have moved away from that. At least with Python, semantic versioning [1] means everyone knows what everyone's talking about. Python 2.8 has to be broadly compatible with 2.7 and doesn't have to be compatible with 3.3. (Which, incidentally, is at odds with some people's idea of a 2.8, which would be incompatible with both. I'm not sure what that would be called - e.1? sqrt(8).0? Something else?) The noise asking for a 2.8 isn't going to die down any time soon. It'll flare up again every time there's a significant event in the 2.7's end of life: when it goes into source-only support, when its python.org support ends entirely, when Debian's next version won't ship it, when Red Hat's ditto ditto, when it's no longer possible to get it from Ubuntu's repositories, etc, etc, etc. And no amount of "There will be no 2.8 unless you make it yourself!" will change that. That's my prediction. ChrisA [1] Not sure if Python's actually stated that http://semver.org/ principles are guaranteed to be followed, but they're certainly approximated to -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On 1/23/2014 7:36 AM, Tim Chase wrote: On 2014-01-23 05:43, Terry Reedy wrote: A list instead of a tuple does work, but not an iterable, so 'sequence'. In the OP's case using sqlite drivers, this is true. However, I maintain some old 2.4 code that uses a correspondingly ancient version of mx.ODBC which requires a tuple and raises an exception on any other iterable. So I always use a tuple out of habit, even if it would be easier to just use some other iterable. I would check 2.7 behavior before changing the 2.7 doc. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Vincent Davis Wrote in message: > I didn't really study the code, and the fact that there's a nested function could mess it up. But if it were a straightforward function with exactly one append, , then replacing the append with a yield would produce the string one character at a time. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 1/23/2014 8:00 PM, Chris Angelico wrote: The noise asking for a 2.8 isn't going to die down any time soon. I suspect you meant "isn't going to die completely" It'll flare up again every time there's a significant event in the 2.7's end of life: when it goes into source-only support, when its python.org support ends entirely, when Debian's next version won't ship it, when Red Hat's ditto ditto, when it's no longer possible to get it from Ubuntu's repositories, etc, etc, etc. And no amount of "There will be no 2.8 unless you make it yourself!" will change that. That's my prediction. Sadly, mine too. Maybe the flareup peaks will gradually become lower. Or maybe they will not be discussed so much on python-list. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On Fri, Jan 24, 2014 at 12:11 PM, Terry Reedy wrote: > On 1/23/2014 8:00 PM, Chris Angelico wrote: > >> The noise asking for a 2.8 isn't going to die down any time soon. > > I suspect you meant "isn't going to die completely" Sorry, yeah. "die off" is the expression I should have used. Presumably it *will* die down in between the renewals, otherwise we wouldn't recognize the renewals. >> It'll flare up again every time there's a significant event in the >> 2.7's end of life: when it goes into source-only support, when its >> python.org support ends entirely, when Debian's next version won't >> ship it, when Red Hat's ditto ditto, when it's no longer possible to >> get it from Ubuntu's repositories, etc, etc, etc. And no amount of >> "There will be no 2.8 unless you make it yourself!" will change that. >> >> That's my prediction. > > Sadly, mine too. Maybe the flareup peaks will gradually become lower. Or > maybe they will not be discussed so much on python-list. Maybe. I suspect that python-list and/or python-dev will see at least some of the traffic, though - when (say) Debian-next is stated as no longer shipping with any Python 2.7, there'll be a bunch of Debian users coming along asking why there won't be a 2.8, and repeat for any other major distribution in place of Debian. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Elementree and insert new element if it is not present
Hi,
I have the following xml,a nd i need to add Description element if it is
not present.
xxxXWorld's
Fastest Indian, The
xxxThe World's Fastest
Indian The World's Fastest Indian
World's Fastest Indian,
The
here is my function.
def insert_description(root,type):
for child in root.findall('.//{
http://schemas.microsoft.com/xxx/2011/06/13/ingest}%s' % type):
title=child.find('.//{
http://schemas.microsoft.com/xxx/2011/06/13/ingestion}Title').text
try:
if child.find('Description') is None:
new_desc = ET.Element('Description')
new_desc.text = title
child.insert(1, new_desc)
except:
pass
root is the xm lfile, type includes (movies,shows,dramas etc)
But this will add the description without checking the "Description" is
exist. i have a problem with the following statement. (i guess)
if child.find('Description') is None:
what i'm doing wrong here, appreciate your help
Regards,
Tharanga
--
https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 2014-01-24 01:00, Chris Angelico wrote: On Fri, Jan 24, 2014 at 11:42 AM, Terry Reedy wrote: Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. Developers informally said 'No 2.8'. People would not believe that. So developers formally said 'No 2.8'. They even inverted the purpose of PEP to make the formal announcement visible and permanent. And a few people still do not want to believe it. Can I get a new version of Java 1.1.8 please? I want it to include all the cool features that I want from the newer versions, but it has to still run all my existing code. I'm not going to put in any effort to actually _make_ this, I want you to do it for me. Actually, the Java versioning system was enough of a mess that, to this day, I don't know what version(s) my old Java code would and wouldn't run on. So glad to have moved away from that. At least with Python, semantic versioning [1] means everyone knows what everyone's talking about. Python 2.8 has to be broadly compatible with 2.7 and doesn't have to be compatible with 3.3. (Which, incidentally, is at odds with some people's idea of a 2.8, which would be incompatible with both. I'm not sure what that would be called - e.1? sqrt(8).0? Something else?) [snip] Python 2.8j? -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
In article , MRAB wrote: > On 2014-01-24 01:00, Chris Angelico wrote: > > On Fri, Jan 24, 2014 at 11:42 AM, Terry Reedy wrote: > >> Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. > >> Developers informally said 'No 2.8'. People would not believe that. So > >> developers formally said 'No 2.8'. They even inverted the purpose of PEP to > >> make the formal announcement visible and permanent. And a few people still > >> do not want to believe it. > > > > Can I get a new version of Java 1.1.8 please? I want it to include all > > the cool features that I want from the newer versions, but it has to > > still run all my existing code. I'm not going to put in any effort to > > actually _make_ this, I want you to do it for me. > > > > Actually, the Java versioning system was enough of a mess that, to > > this day, I don't know what version(s) my old Java code would and > > wouldn't run on. So glad to have moved away from that. At least with > > Python, semantic versioning [1] means everyone knows what everyone's > > talking about. Python 2.8 has to be broadly compatible with 2.7 and > > doesn't have to be compatible with 3.3. (Which, incidentally, is at > > odds with some people's idea of a 2.8, which would be incompatible > > with both. I'm not sure what that would be called - e.1? sqrt(8).0? > > Something else?) > > > [snip] > Python 2.8j? You're imagining things. -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> Python 2.8j? > > You're imagining things. Get real... s'not gonna happen. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
In article , Chris Angelico wrote: > On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: > >> Python 2.8j? > > > > You're imagining things. > > Get real... s'not gonna happen. > I wouldn't bet on that. The situation keeps getting tensor and tensor. -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On Fri, Jan 24, 2014 at 1:34 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> >> Python 2.8j? >> > >> > You're imagining things. >> >> Get real... s'not gonna happen. >> > I wouldn't bet on that. The situation keeps getting tensor and tensor. I can't complain, really. This was a perfectly rational discussion until I suggested "e.1". ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Elementree and insert new element if it is not present - FIXED
manged to fix it. need to add the namespace when checking the condition. Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote:
> Hi,
>
>
>
> I want to show a code for review but afraid of plagiarism issues. Kindly,
> suggest how can I post it for review here without masking it visible for
> public
Thanks
config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3':
['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01',
'192.168.0.1', '200']}
What if I want to search for a particular value inside the lists of all keys
except one that user inputs and also want to print that value.
Forexample, user gets prompt to enter following four parameters
prompt1= "Enter "
After user has input I have added this information into above
dictionary(config_database) but I also need to check if this ip is not already
assigned to a PC other than the one which user inputs. So how to search for
particular value inside the lists associated with keys other than inside that
one which user inputs(because obviously then it would match so just want to
skip its own entry) and print that value.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Initialise dictionary of dictionary
Thank you so much Tim. This is precisely what I wanted to do!
On Thursday, January 23, 2014 9:00:23 PM UTC+5:30, Tim Chase wrote:
> On 2014-01-23 07:15, Ayushi Dalmia wrote:
>
> > I need to initialise a dictionary of dictionary with float values.
>
> > I do not know the size of the dictionary beforehand. How can we do
>
> > that in Python --
>
>
>
> Either
>
>
>
> d = {}
>
>
>
> or, if you want
>
>
>
> from collections import defaultdict
>
> d = defaultdict(float)
>
> print(d["Hello"])
>
>
>
> If you really do want a dict-of-dict that defaults to floats, you can
>
> do
>
>
>
> d = defaultdict(lambda: defaultdict(float))
>
> print(d[3141]["Hello"])
>
>
>
> -tkc
--
https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Friday, January 24, 2014 8:45:51 AM UTC+5:30, indar kumar wrote:
> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote:
>
> > Hi,
>
> >
>
> >
>
> >
>
> > I want to show a code for review but afraid of plagiarism issues. Kindly,
> > suggest how can I post it for review here without masking it visible for
> > public
>
>
>
> Thanks
>
>
>
> config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3':
> ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01',
> '192.168.0.1', '200']}
>
>
>
> What if I want to search for a particular value inside the lists of all keys
> except one that user inputs and also want to print that value.
>
>
>
> Forexample, user gets prompt to enter following four parameters
>
> prompt1= "Enter "
>
>
>
> After user has input I have added this information into above
> dictionary(config_database) but I also need to check if this ip is not
> already assigned to a PC other than the one which user inputs. So how to
> search for particular value inside the lists associated with keys other than
> inside that one which user inputs(because obviously then it would match so
> just want to skip its own entry) and print that value.
Does this suggest some ideas to you??
>>> config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3':
>>> ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01',
>>> '192.168.0.1', '200']}
>>> {pc:config_database[pc][1] for pc in config_database.keys()}
{'PC2': '192.168.0.2', 'PC3': '192.168.0.3', 'PC1': '192.168.0.1'}
Or even simpler
>>> {pc:config_database[pc][1] for pc in config_database}
{'PC2': '192.168.0.2', 'PC3': '192.168.0.3', 'PC1': '192.168.0.1'}
--
https://mail.python.org/mailman/listinfo/python-list
Re: datetime as subclass of date
Roy Smith writes: > Ben Finney wrote: > > > Makes sense, since ‘datetime’ can do everything ‘date’ can do, and > > is conceptually a subset of the same concept. > > That's reasonable, but given that, it's weird that date(2014, 1, 23) == > datetime(2014, 1, 23) is False. You would think it should be True, in > the same way that 1 + 0j == 1 is True. Hmm. It does make sense to me that ‘datetime.date(2014, 1, 23) == datetime.datetime(2014, 1, 23)’. I can come up with rationalisations for why it isn't, but they're not satisfactory. I also don't consider it a bug, though. I'm conflicted :-) -- \ “Those who write software only for pay should go hurt some | `\ other field.” —Erik Naggum, in _gnu.misc.discuss_ | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Yes now I want to search for an ip that user has input but skipping the key which user has input. e.g. user entered PC1 and 192.168.0.1. Now I want to scan through config_database to see if this ip is already in it. But PC1 192.168.0.1 is added to config_database before searching so I want to skip PC1 key during searching so that I can see if this Ip is not already associated with any other host. -- https://mail.python.org/mailman/listinfo/python-list
