Re: What is the recommended python module for SQL database access?
As Chris said, if your needs are simple, use SQLite back-end. It's probably already installed on your computer and Python has a nice interface to it in its standard library. [1] If you decide to use MySQL back-end instead, consider using PyMySQL [2]. It's compatible with both Python 2 and Python 3. Also, being written in pure Python, it's easier to install compared to MySQLdb. [1] http://docs.python.org/3/library/sqlite3.html#module-sqlite3 [2] https://pypi.python.org/pypi/PyMySQL 2014-02-08 6:55 GMT-02:00 Sam : > Is MySQLdb the recommended python module for SQL database access? Are > there other modules? What I want in a module is to be able to write > readable and maintainable code. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
system wide mutex
Hi Which one is most recommended to use for mutex alike locking to achieve atomic access to single resource: - fcntl.lockf - os.open() with O_SHLOCK and O_EXLOCK - https://pypi.python.org/pypi/lockfile/0.9.1 - https://pypi.python.org/pypi/zc.lockfile/1.1.0 - any other ? Thanks /Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Why use _mysql module and not use MySQLdb directly?
Another option is PyMySQL [1]. It's developed in the open at GitHub [2]. It's pure Python, compatible with both Python 2 and Python 3. It's DB-API 2 compliant. It also implements some non-standard bits that are present in MySQLdb, in order to be compatible with legacy code, notably Django (personally, I consider the use of non-standard API from a DB adapter a bug, but while the big projects don't fix it, we have to work around it). [1] https://pypi.python.org/pypi/PyMySQL [2] https://github.com/PyMySQL/PyMySQL 2014-02-08 10:09 GMT-02:00 Asaf Las : > On Saturday, February 8, 2014 1:42:30 PM UTC+2, Chris Angelico wrote: > > On Sat, Feb 8, 2014 at 10:32 PM, Asaf Las wrote: > > > > > Hi Chris > > > The doc says > > > https://pypi.python.org/pypi/mysql-connector-python/1.1.5 > > > MySQL driver written in Python which does not depend on MySQL C > > > client libraries and implements the DB API v2.0 specification > (PEP-249). > > > > Ah. And that links to dev.mysql.com, so it's presumably the same > > thing... would be nice if they'd say that on their own site. That's > > what I was looking for, anyhow. Confirms the suspicion. > > > > There may well be performance differences between pure-Python > > implementations and ones that go via C, but having used a > > pure-high-level-language implementation of PostgreSQL's wire protocol > > (granted, that was Pike, which is a somewhat higher performance > > language than Python, but same difference), I can assure you of what > > ought to be obvious anyway: that performance is dominated by the > > server's throughput and thus (usually) by disk speed. So it's going to > > be pretty much the same with all of them; look for ancillary features > > that might make your life easier, otherwise pick whichever you like. > > > > ChrisA > > Hmmm, they say : > > http://dev.mysql.com/doc/connector-python/en/connector-python-introduction.html > > "MySQL Connector/Python enables Python programs to access MySQL databases, > using an API that is compliant with the Python DB API version 2.0. It > is written in pure Python and does not have any dependencies except for > the Python Standard Library..." > > i guess with Oracle connector there could be one advantage - they will > try to be most compliant to their product in every aspect as they would > raiser promote their DB instead of discouraging from it. > > /Asaf > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: What are the kinds of software that are not advisable to be developed using Python?
Le dimanche 9 février 2014 06:17:03 UTC+1, Skybuck Flying a écrit : > " > > > > > However there is more... Python may lack some technical language elements > > like, call by reference, and perhaps other low level codes, like 8 bit, 16 > > bit, 32 bit integers which play a roll with interfacing with hardware. > > > Or, pure software, interfacing with the unicode transformation units! jmf -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On Sun, Feb 9, 2014 at 9:20 PM, Marcel Rodrigues wrote: > As Chris said, if your needs are simple, use SQLite back-end. It's probably > already installed on your computer and Python has a nice interface to it in > its standard library. Already installed? I thought the point of SQLite3 being in the Python stdlib was that Python actually included the entire engine (that's why there's no, for instance, PostgreSQL client in the stdlib - because there's no server; I disagree with the reasoning, but it is consistent and valid), so you don't need _anything_ externally installed. In any case, SQLite is ideal for really simple databasing. Back in the 1990s, I had DB2, DB2, and DB2, for all my database work. I wanted a way to query a dictionary of English words using SQL, so I created a DB2 database and threw ~60K rows into a table. Massive overkill for a one-column table. These days, I could use SQLite (or more likely, just use grep on /usr/share/dict/words - grep does everything that I wanted SQL for, if you include piping from one grep into another), cutting the overhead down enormously. The biggest downside of SQLite3 is concurrency. I haven't dug into the exact details of the pager system and such, but it seems to be fairly coarse in its locking. Also, stuff gets a bit complicated when you do a single transaction involving multiple files. So if you have lots of processes writing to the same set of SQLite tables, you'll see pretty poor performance. PostgreSQL handles that situation far better, but has a lot more overhead, so it's a poor choice for a single simple application. MySQL's locking/concurrency system is specifically optimized for a model that's common for web applications: a huge number of readers and a tiny number of writers (sometimes referred to as Data Warehousing, because you basically stuff a warehouse full of data and then everyone comes looking for it). For the write-heavy model (sometimes called OLTP or On-Line Transaction Processing), PostgreSQL will hugely outperform MySQL, thanks to its MVCC model. Broad recommendation: Single application, tiny workload, concurrency not an issue, simplicity desired? Go SQLite. Big complex job, need performance, lots of things reading and writing at once, want networked access? Go PGSQL. And don't go MySQL if PG is an option. And definitely don't go for a non-free option (MS-SQL, DB2, etc) unless you've looked into it really closely and you are absolutely thoroughly *sure* that you need that system (which probably means you need your app to integrate with someone else's, and that other app demands one particular database). ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
> Which one is most recommended to use for mutex alike locking to > achieve atomic access to single resource: > > - fcntl.lockf > - os.open() with O_SHLOCK and O_EXLOCK > - https://pypi.python.org/pypi/lockfile/0.9.1 > - https://pypi.python.org/pypi/zc.lockfile/1.1.0 > - any other ? As the author of lockfile, I can tell you it only implements advisory locking. All programs needing to access the locked resources must cooperate. It also has bugs which have been reported which I have yet to spend any time fixing. Beyond that, your question isn't really detailed enough to answer completely. You don't identify what sort of systems you need this to work on (Windows, Mac, various flavors of Unix?), whether programs written in other languages will be involved (you did say "system wide"), and whether you need to use it in the face of network file systems like NFS or Samba. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
Forget to mentioned - CentOS 6.5 Python v3.3. -- https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
On Sunday, February 9, 2014 1:00:39 PM UTC+2, Skip Montanaro wrote: > > Which one is most recommended to use for mutex alike locking to > > achieve atomic access to single resource: > > > > - fcntl.lockf > > - os.open() with O_SHLOCK and O_EXLOCK > > - https://pypi.python.org/pypi/lockfile/0.9.1 > > - https://pypi.python.org/pypi/zc.lockfile/1.1.0 > > - any other ? > > As the author of lockfile, I can tell you it only implements advisory > locking. All programs needing to access the locked resources must > cooperate. It also has bugs which have been reported which I have yet > to spend any time fixing. > Beyond that, your question isn't really detailed enough to answer > completely. You don't identify what sort of systems you need this to > work on (Windows, Mac, various flavors of Unix?), whether programs > written in other languages will be involved (you did say "system > wide"), and whether you need to use it in the face of network file > systems like NFS or Samba. > Skip Hi Yes i realized that missed info. The lock is needed for 2 independently spawned processes to update set of files and non non thread safe db /Asaf -- https://mail.python.org/mailman/listinfo/python-list
Event::wait with timeout gives delay
Running Python 2.6 and 2.7 on Windows 7 and Server 2012 Event::wait causes a delay when used with a timeout that is not triggered because event is set in time. I don't understand why. Can someone explain? The following program shows this; '''Shows that using a timeout in Event::wait (same for Queue::wait) causes a delay. This is perhaps caused by a polling loop inside the wait implementation. This polling loop sleeps some time depending on the timeout. Probably wait timeout > 1ms => sleep = 1ms A wait with timeout can take at least this sleep time even though the event is set or queue filled much faster.''' import threading event1 = threading.Event() event2 = threading.Event() def receiver(): '''wait 4 event2, clear event2 and set event1.''' while True: event2.wait() event2.clear() event1.set() receiver_thread = threading.Thread(target = receiver) receiver_thread.start() def do_transaction(timeout): '''Performs a transaction; clear event1, set event2 and wait for thread to set event1.''' event1.clear() event2.set() event1.wait(timeout = timeout) while True: # With timeout None this runs fast and CPU bound. # With timeout set to some value this runs slow and not CPU bound. do_transaction(timeout = 10.0) -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
I just checked in the Python sources and apparently you're right about SQLite3. The Python distribution includes pysqlite which seems to be a self-contained SQLite engine. No external dependencies. Sorry for the confusion. 2014-02-09 9:00 GMT-02:00 Chris Angelico : > On Sun, Feb 9, 2014 at 9:20 PM, Marcel Rodrigues > wrote: > > As Chris said, if your needs are simple, use SQLite back-end. It's > probably > > already installed on your computer and Python has a nice interface to it > in > > its standard library. > > Already installed? I thought the point of SQLite3 being in the Python > stdlib was that Python actually included the entire engine (that's why > there's no, for instance, PostgreSQL client in the stdlib - because > there's no server; I disagree with the reasoning, but it is consistent > and valid), so you don't need _anything_ externally installed. > > In any case, SQLite is ideal for really simple databasing. Back in the > 1990s, I had DB2, DB2, and DB2, for all my database work. I wanted a > way to query a dictionary of English words using SQL, so I created a > DB2 database and threw ~60K rows into a table. Massive overkill for a > one-column table. These days, I could use SQLite (or more likely, just > use grep on /usr/share/dict/words - grep does everything that I wanted > SQL for, if you include piping from one grep into another), cutting > the overhead down enormously. > > The biggest downside of SQLite3 is concurrency. I haven't dug into the > exact details of the pager system and such, but it seems to be fairly > coarse in its locking. Also, stuff gets a bit complicated when you do > a single transaction involving multiple files. So if you have lots of > processes writing to the same set of SQLite tables, you'll see pretty > poor performance. PostgreSQL handles that situation far better, but > has a lot more overhead, so it's a poor choice for a single simple > application. MySQL's locking/concurrency system is specifically > optimized for a model that's common for web applications: a huge > number of readers and a tiny number of writers (sometimes referred to > as Data Warehousing, because you basically stuff a warehouse full of > data and then everyone comes looking for it). For the write-heavy > model (sometimes called OLTP or On-Line Transaction Processing), > PostgreSQL will hugely outperform MySQL, thanks to its MVCC model. > > Broad recommendation: Single application, tiny workload, concurrency > not an issue, simplicity desired? Go SQLite. Big complex job, need > performance, lots of things reading and writing at once, want > networked access? Go PGSQL. And don't go MySQL if PG is an option. > > And definitely don't go for a non-free option (MS-SQL, DB2, etc) > unless you've looked into it really closely and you are absolutely > thoroughly *sure* that you need that system (which probably means you > need your app to integrate with someone else's, and that other app > demands one particular database). > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On Sun, Feb 9, 2014 at 11:04 PM, Marcel Rodrigues wrote: > I just checked in the Python sources and apparently you're right about > SQLite3. The Python distribution includes pysqlite which seems to be a > self-contained SQLite engine. No external dependencies. Sorry for the > confusion. Comes to the same thing, anyhow. If anything, that strengthens your original point: it's easy, it's right there, you can give it a go. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Sort one sequence by O(n) in time and O(1) in space
Hi guys, Here is one question related to algorithm. Details here: here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with time complexity as O(n) and space as O(1). Any comments will be appreciated. Thanks. Wesley -- https://mail.python.org/mailman/listinfo/python-list
Help!
I have studied python(2.7.2) till classes. I have covered most of the the general topics. But i do not know how to apply this. Can someone help me? I want to make something that can aid me financially. If you have done something like this please can you provide me with the resources and the libraries so that i may study even further. Thanks You! -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
On Sunday, February 9, 2014 2:13:50 PM UTC+2, Wesley wrote: > Hi guys, >Here is one question related to algorithm. > Details here: > > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > time complexity as O(n) and space as O(1). > > Any comments will be appreciated. > > Thanks. > > Wesley if space O(1) is needed they don't have to be merged - list alike class keeping series as members returning a[i] if i is odd and b[i] if i is even would be enough. then constructing such sequence (or class instance) will be done in O(1) as well. /Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
On Sun, Feb 9, 2014 at 11:13 PM, Wesley wrote: > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > time complexity as O(n) and space as O(1). The two halves of the list are already sorted, yes? Then you don't need a sort operation, just a zip. def flip_list(lst): offset = len(lst)//2 for i in range(offset): yield lst[i] yield lst[i+offset] start = ['a1','a2','a3','a4','b1','b2','b3','b4'] result = list(flip_list(start)) print(result) Alternatively, you could arrange this as some kind of swap operation, modifying the list in place, but I think the more Pythonic way will be to create a new list. Note that, with the function defined as I have above, you can iterate over the flipped list without actually coalescing it in memory. That gives effective O(1) space, and it's definitely O(n) time as it simply iterates over the whole list once. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!
On Sun, Feb 9, 2014 at 11:25 PM, Moz wrote: > I have studied python(2.7.2) till classes. I have covered most of the the > general topics. But i do not know how to apply this. Can someone help me? I > want to make something that can aid me financially. If you have done > something like this please can you provide me with the resources and the > libraries so that i may study even further. > Thanks You! The best way to apply your new knowledge is to find some problem and use Python to solve it. What are you doing every day, manually, that could be automated? Or maybe it's not something you do every day, but when you do it, you have a batch of them. Find some job that you think "A computer ought to be able to do this!" about, and teach the computer to do it :) Once you get into the habit of doing that, you'll be a programmer/sysadmin with a comfortable set of tools and an attitude that lends itself well to getting the job done efficiently. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On Sunday, February 9, 2014 1:00:58 PM UTC+2, Chris Angelico wrote:
> The biggest downside of SQLite3 is concurrency. I haven't dug into the
> exact details of the pager system and such, but it seems to be fairly
> coarse in its locking. Also, stuff gets a bit complicated when you do
> a single transaction involving multiple files. So if you have lots of
> processes writing to the same set of SQLite tables, you'll see pretty
> poor performance.
> ChrisA
Hi Chris
i simply tested running 2 independent processes started at same time in
parallel towards same sqlite database and never get 2 in that row
though used exclusive lock on DB. might be i did something wrong.
p.s. threading locks don't do anything in this example.
import sqlite3
import threading
#from threading import Lock
# Constants
CNT_DB_NAME = "messageid.db"
class MessageId:
'''
--
Following must be done in advance:
- Create DB sqlite3 sqlite_msgd.db
- Create table CREATE TABLE msgid (id INTEGER PRIMARY KEY, val
INTEGER);
- Inser def INSERT INTO msgid VALUES (0, 0);
--'''
def __init__(self, dflag = False, dbname = 'messageid.db'):
#print(type(self))
#print(id(self))
self._debug = dflag
self._lock = threading.Lock()
self._dbname = dbname
if self._debug:
print("MessageId.__init__(dbname = {0})".format(dbname))
def get_msgid(self):
'''
--
- Acquire lock
- Connect to database
- Select current value SELECT val FROM msgid WHERE id = 0;
- Increment current value
- Insert a row of data UPDATE msgid SET val = 1 WHERE id =
new_val;
--'''
self._lock.acquire(True, 1)
conn = sqlite3.connect('example.db', 10.0, True, "EXCLUSIVE")
c = conn.cursor()
c.execute("SELECT val FROM msgid WHERE id = 0")
tint = int(c.fetchone()[0]) + 1
c.execute("UPDATE msgid SET val={0} WHERE id = 0".format(tint))
conn.commit()
conn.close()
self._lock.release()
if self._debug:
print("MessageId.get_msgid() = ", tint)
return tint
tclass = MessageId()
for k in range(1):
tclass.get_msgid()
--
https://mail.python.org/mailman/listinfo/python-list
imperative mood in docstrings
pep 257 -- docstring conventions, as well as a myriad of books and other
resources, recommend documenting a function's or method's effect as a command
("do this", "return that"), not as a description ("does this", "returns that").
what's the logic behind this recommendation?
bagratte
--
https://mail.python.org/mailman/listinfo/python-list
Re: Help!
On Sunday, February 9, 2014 5:42:09 PM UTC+5, Chris Angelico wrote: > On Sun, Feb 9, 2014 at 11:25 PM, Moz wrote: > > > I have studied python(2.7.2) till classes. I have covered most of the the > > general topics. But i do not know how to apply this. Can someone help me? I > > want to make something that can aid me financially. If you have done > > something like this please can you provide me with the resources and the > > libraries so that i may study even further. > > > Thanks You! > > > > The best way to apply your new knowledge is to find some problem and > > use Python to solve it. What are you doing every day, manually, that > > could be automated? Or maybe it's not something you do every day, but > > when you do it, you have a batch of them. Find some job that you think > > "A computer ought to be able to do this!" about, and teach the > > computer to do it :) Once you get into the habit of doing that, you'll > > be a programmer/sysadmin with a comfortable set of tools and an > > attitude that lends itself well to getting the job done efficiently. > > > > ChrisA Thanks :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!
On Sunday, February 9, 2014 2:25:16 PM UTC+2, Moz wrote: > I want to make something that can aid me financially. If you have > done something like this please can you provide me with the resources > and the libraries so that i may study even further. > > Thanks You! you can try similar to this : http://www.rent-acoder.com find the task you can't do but can figure out and gain in knowledge i never used such sites, only sporadic references from from whom i know. -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On Sun, Feb 9, 2014 at 11:47 PM, Asaf Las wrote:
> i simply tested running 2 independent processes started at same time in
> parallel towards same sqlite database and never get 2 in that row
> though used exclusive lock on DB. might be i did something wrong.
The threading locks aren't doing anything, because you don't have
multiple threads here; what you need is SQLite locks, which you'll
already have.
I don't know why it wouldn't work. Unfortunately I wasn't able to test
your code directly - SQLite complained that the table didn't exist,
despite my having created it (at least, so I thought) in interactive
Python. So probably I mucked something up there. Someone who actually
knows SQLite might be better able to explain.
A few points, though.
> c.execute("UPDATE msgid SET val={0} WHERE id = 0".format(tint))
Don't do this; instead, let c.execute() do the interpolation, by
giving it extra args rather than using .format(). It makes no
difference when you're working with integers, but with strings, it
makes the difference between safe and not-safe (or easy and
unnecessarily fiddly, if you actually take the time to get your
escaping right).
Also, you're connecting and disconnecting repeatedly... oh, I see why
it didn't work when I tried. You're also using two completely
different database names: 'messageid.db' which is named in a constant
and in the default argument, and 'example.db' which is what you
actually use. Should have a single source of truth, otherwise you
confuse the people who might otherwise be able to test your code :)
Anyway. This code is extremely inefficient:
>conn = sqlite3.connect('example.db', 10.0, True, "EXCLUSIVE")
>c = conn.cursor()
>c.execute("SELECT val FROM msgid WHERE id = 0")
>tint = int(c.fetchone()[0]) + 1
>c.execute("UPDATE msgid SET val={0} WHERE id = 0".format(tint))
>conn.commit()
>conn.close()
Much more common would be to retain a connection and repeatedly
perform queries. Then you won't need to open it EXCLUSIVE, and you can
simply query, update, and then commit (all your locks should be
released at the commit). Do that, and you should see at least
reasonable performance, plus everything should work correctly.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On Sunday, February 9, 2014 3:14:50 PM UTC+2, Chris Angelico wrote:
> On Sun, Feb 9, 2014 at 11:47 PM, Asaf Las wrote:
>
Thanks
>
> Also, you're connecting and disconnecting repeatedly... oh, I see why
> it didn't work when I tried. You're also using two completely
> different database names: 'messageid.db' which is named in a constant
> and in the default argument, and 'example.db' which is what you
> actually use. Should have a single source of truth, otherwise you
> confuse the people who might otherwise be able to test your code :)
my apologies , it was deep night, when i got disappointed and forget to
update names so left as it is and did not check when posted :-)
> Anyway. This code is extremely inefficient:
>
> >conn = sqlite3.connect('example.db', 10.0, True, "EXCLUSIVE")
> >c = conn.cursor()
> >c.execute("SELECT val FROM msgid WHERE id = 0")
> >tint = int(c.fetchone()[0]) + 1
> >c.execute("UPDATE msgid SET val={0} WHERE id = 0".format(tint))
> >conn.commit()
> >conn.close()
>
> Much more common would be to retain a connection and repeatedly
> perform queries. Then you won't need to open it EXCLUSIVE, and you can
> simply query, update, and then commit (all your locks should be
> released at the commit). Do that, and you should see at least
> reasonable performance, plus everything should work correctly.
> ChrisA
i did it just to test sqlite3 behavior and actually test was related to
simulation of unique incremental sequence number/counter for
independently spawned tasks accessing counter in non deterministic manner.
/Asaf
--
https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On Mon, Feb 10, 2014 at 12:27 AM, Asaf Las wrote: > i did it just to test sqlite3 behavior and actually test was related to > simulation of unique incremental sequence number/counter for > independently spawned tasks accessing counter in non deterministic manner. Sure. I would expect that you'd get steadily increasing sequence IDs, but that they might be a major bottleneck. SQLite is (far as I can tell, at least - haven't personally tested it) quite solid with its locking; at the expense of performance, but carefully reliable. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
On 9 February 2014 12:13, Wesley wrote: > Hi guys, >Here is one question related to algorithm. > Details here: > > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > time complexity as O(n) and space as O(1). Do you mean that you have a list and you want to rearrange the elements in-place without creating a new list? Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!
On Sunday, February 9, 2014 5:54:16 PM UTC+5, Asaf Las wrote: > On Sunday, February 9, 2014 2:25:16 PM UTC+2, Moz wrote: > > > I want to make something that can aid me financially. If you have > > > done something like this please can you provide me with the resources > > > and the libraries so that i may study even further. > > > > > > Thanks You! > > > > you can try similar to this : > > > > http://www.rent-acoder.com > > > > find the task you can't do but can figure out and gain in knowledge > > i never used such sites, only sporadic references from from whom i know. Thanks :) -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On 2014-02-09 22:00, Chris Angelico wrote: > On Sun, Feb 9, 2014 at 9:20 PM, Marcel Rodrigues > wrote: > > As Chris said, if your needs are simple, use SQLite back-end. > > It's probably already installed on your computer and Python has a > > nice interface to it in its standard library. > > Already installed? I thought the point of SQLite3 being in the > Python stdlib was that Python actually included the entire engine It's been a part of the stdlib since 2.5 (so those of us that maintain a bit of 2.4 code still in the wild had to add-on that module) -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
Please reply to the list rather than directly to me so that other people can see the answer to my question and offer you help. On 9 February 2014 14:04, Ni Wesley wrote: > 2014年2月9日 下午9:41于 "Oscar Benjamin" 写道: > >> On 9 February 2014 12:13, Wesley wrote: >> > Hi guys, >> >Here is one question related to algorithm. >> > Details here: >> > >> > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx >> > always exist in pair. So, now, how to change the sequence to >> > a1,b1,...,an,bn, with time complexity as O(n) and space as O(1). >> >> Do you mean that you have a list and you want to rearrange the >> elements in-place without creating a new list? > > Yes Okay so if you're going to do it with O(1) space then it's going to have to be done with a whole bunch of swaps. Have a think with pen and paper about how you could do a sequence of swaps that would rearrange the order to the one that you want (it's actually a harder problem than it looks at first glance). This is an example of what is known as "transposition" and much information is available about algorithms for doing this in-place: http://en.wikipedia.org/wiki/In-place_matrix_transposition Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
Yes, with no new list, otherwise, space won't to be O(1) Wesley 2014年2月9日 下午10:31于 "Oscar Benjamin" 写道: > Please reply to the list rather than directly to me so that other > people can see the answer to my question and offer you help. > > On 9 February 2014 14:04, Ni Wesley wrote: > > 2014年2月9日 下午9:41于 "Oscar Benjamin" 写道: > > > >> On 9 February 2014 12:13, Wesley wrote: > >> > Hi guys, > >> >Here is one question related to algorithm. > >> > Details here: > >> > > >> > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx > >> > always exist in pair. So, now, how to change the sequence to > >> > a1,b1,...,an,bn, with time complexity as O(n) and space as O(1). > >> > >> Do you mean that you have a list and you want to rearrange the > >> elements in-place without creating a new list? > > > > Yes > > Okay so if you're going to do it with O(1) space then it's going to > have to be done with a whole bunch of swaps. Have a think with pen and > paper about how you could do a sequence of swaps that would rearrange > the order to the one that you want (it's actually a harder problem > than it looks at first glance). This is an example of what is known as > "transposition" and much information is available about algorithms for > doing this in-place: > http://en.wikipedia.org/wiki/In-place_matrix_transposition > > > Oscar > -- https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
In article , Skip Montanaro wrote: > > Which one is most recommended to use for mutex alike locking to > > achieve atomic access to single resource: > > > > - fcntl.lockf > > - os.open() with O_SHLOCK and O_EXLOCK > > - https://pypi.python.org/pypi/lockfile/0.9.1 > > - https://pypi.python.org/pypi/zc.lockfile/1.1.0 > > - any other ? > > As the author of lockfile, I can tell you it only implements advisory > locking. All programs needing to access the locked resources must > cooperate. This is true of all mutexes, no? We needed a mutex that worked across multiple machines, so we ended up implementing a mutex in memcache. We based ours on http://tinyurl.com/lybx2kl, but if you google for "memcache mutex python", you'll find a number of implementations. -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
In article ,
Wesley wrote:
> Hi guys,
>Here is one question related to algorithm.
> Details here:
>
> here is input sequence like a1,a2,...,an,b1,b2,...,bn ï¼the ax and bx always
> exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with
> time complexity as O(n) and space as O(1).
Is this a homework problem?
It sounds like what you want to do is split the list into two halves, then
shuffle them. Using
itertools let's you do these operations without making copies of the data.
Something like:
--
from itertools import islice, izip
def cut_and_shuffle(input):
n = len(input)
if n % 2:
raise ValueError("input length must be even")
split = n/2
print "split =", split
first_half = islice(input, 0, split)
second_half = islice(input, split, n)
for a, b in izip(first_half, second_half):
yield a
yield b
l = ['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4']
print list(cut_and_shuffle(l))
--
$ python shuffle.py
split = 4
['a1', 'b1', 'a2', 'b2', 'a3', 'b3', 'a4', 'b4']
--
https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
On Sun, Feb 9, 2014 at 8:45 AM, Roy Smith wrote: > This is true of all mutexes, no? Hmmm... You might well be right. I thought that use of the O_EXLOCK flag in the open(2) system call would prevent other processes from opening the file, but (at least on my Mac) it just blocks until the first process closes the file. Perhaps there are some other flags you can use to cause the second open(2) call to error out. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
Please don't top-post. On Feb 9, 2014 2:40 PM, "Ni Wesley" wrote: > > Yes, with no new list, otherwise, space won't to be O(1) Did you read the link I posted: >> http://en.wikipedia.org/wiki/In-place_matrix_transposition Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: What are the kinds of software that are not advisable to be developed using Python?
On 09/02/2014 10:47, [email protected] wrote: Le dimanche 9 février 2014 06:17:03 UTC+1, Skybuck Flying a écrit : " However there is more... Python may lack some technical language elements like, call by reference, and perhaps other low level codes, like 8 bit, 16 bit, 32 bit integers which play a roll with interfacing with hardware. Or, pure software, interfacing with the unicode transformation units! jmf You missed this :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!
On 09/02/2014 13:52, Moz wrote: On Sunday, February 9, 2014 5:54:16 PM UTC+5, Asaf Las wrote: On Sunday, February 9, 2014 2:25:16 PM UTC+2, Moz wrote: I want to make something that can aid me financially. If you have done something like this please can you provide me with the resources and the libraries so that i may study even further. Thanks You! you can try similar to this : http://www.rent-acoder.com find the task you can't do but can figure out and gain in knowledge i never used such sites, only sporadic references from from whom i know. Thanks :) I'm pleased to see that you have answers. In return would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
Asaf Las :
> Which one is most recommended to use for mutex alike locking to
> achieve atomic access to single resource:
>
> - fcntl.lockf
I recommend fcntl.flock:
#!/usr/bin/python3
import sys, fcntl, time
with open("test.lock", "w+") as lock:
fcntl.flock(lock.fileno(), fcntl.LOCK_EX)
# begin critical
sys.stdout.write("hello\n")
time.sleep(3)
sys.stdout.write("world\n")
# end critical
Marko
--
https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
In article ,
bagrat lazaryan wrote:
> pep 257 -- docstring conventions, as well as a myriad of books and other
> resources, recommend documenting a function's or method's effect as a command
> ("do this", "return that"), not as a description ("does this", "returns
> that"). what's the logic behind this recommendation?
>
> bagratte
Methods are verbs, and should be described as such. If I had:
class Sheep:
def fly(self):
"Plummet to the ground."
I'm defining the action the verb performs. If, on the other hand, I had:
class Sheep:
def fly(self):
"Plummets to the ground"
I'm no longer describing the action of flying, I'm describing what the
sheep does when it attempts to perform that action.
--
https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
On 09/02/2014 12:05, bagrat lazaryan wrote:
pep 257 -- docstring conventions, as well as a myriad of books and other resources, recommend documenting a function's
or method's effect as a command ("do this", "return that"), not as a description ("does
this", "returns that"). what's the logic behind this recommendation?
bagratte
I can't really answer your question as I don't understand why docstrings
should get moody, or did you mean mode? :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com
--
https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
Mark Lawrence writes:
> On 09/02/2014 12:05, bagrat lazaryan wrote:
>
> > pep 257 -- docstring conventions, as well as a myriad of books and
> > other resources, recommend documenting a function's or method's
> > effect as a command ("do this", "return that"), not as a
> > description ("does this", "returns that"). what's the logic behind
> > this recommendation?
>
> I can't really answer your question as I don't understand why
> docstrings should get moody, or did you mean mode? :)
--
https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
Hi Thanks for replies. It would be good to have blocking implementation. I have to check fcntl if it works in blocking mdoe on CentOS. Meanwhile there is Posix Semaphore made for Python: http://semanchuk.com/philip/posix_ipc/ will try it as well. /Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
On Sun, Feb 9, 2014 at 5:52 PM, Roy Smith wrote:
> In article ,
> bagrat lazaryan wrote:
>
>> pep 257 -- docstring conventions, as well as a myriad of books and other
>> resources, recommend documenting a function's or method's effect as a command
>> ("do this", "return that"), not as a description ("does this", "returns
>> that"). what's the logic behind this recommendation?
>>
>> bagratte
>
> Methods are verbs, and should be described as such. If I had:
>
> class Sheep:
>def fly(self):
> "Plummet to the ground."
>
> I'm defining the action the verb performs. If, on the other hand, I had:
>
> class Sheep:
>def fly(self):
> "Plummets to the ground"
>
> I'm no longer describing the action of flying, I'm describing what the
> sheep does when it attempts to perform that action.
This can also be seen with a (monolingual) dictionary. For example:
https://www.google.com/search?q=define+fly (that’s actually from the
New Oxford American Dictionary):
fly, verb: 1. move through the air under control. 2. move or be hurled
quickly through the air.
Those could be valid docstrings (if sheep could fly, of course…) — so,
in other words, act as if you were writing a dictionary and not Python
code.
--
Chris “Kwpolska” Warrick
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
--
https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
On 02/09/2014 08:52 AM, Roy Smith wrote:
In article ,
bagrat lazaryan wrote:
pep 257 -- docstring conventions, as well as a myriad of books and other
resources, recommend documenting a function's or method's effect as a command
("do this", "return that"), not as a description ("does this", "returns
that"). what's the logic behind this recommendation?
bagratte
Methods are verbs, and should be described as such. If I had:
class Sheep:
def fly(self):
"Plummet to the ground."
I'm defining the action the verb performs. If, on the other hand, I had:
Shouldn't that be:
class Pig:
def fly(self):
"Soar gracefully through the air if a hot place is very cold."
if hell is frozen:
self.sprout_wings()
self.altitude += 10
self.velocity += 25
else:
self.splat()
;)
--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
On 2/9/2014 7:05 AM, bagrat lazaryan wrote:
pep 257 -- docstring conventions, as well as a myriad of books and other resources, recommend documenting a function's
or method's effect as a command ("do this", "return that"), not as a description ("does
this", "returns that"). what's the logic behind this recommendation?
The imperative is directed at the Python interpreter. It says what a
call instructs the interpreter to do.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Python (?) webserver for WSGI
Dear List, What is the latest "best-practice" for deploying a python wsgi application into production? For development, I've been using CherryPyWSGIServer which has been working very well (and the code is small enough to actually ship with my application). But I would like some way of deploying a server listening on port 80 (and then dropping root privileges). I have looked at using gunicorn + ngnix, but that gives me 3 layers that I need to set up: - my own application - gunicorn - ngnix Compared to using something like CherryPyWSGIServer (where a single line of code starts my application!) that seems like overkill and rather complicated for a small application. I'm not expecting 1000s of users (or even dozens!), but this is an application that will be accessible to "the internet" and so server security is a concern (which is why I don't want to use anything that labels itself as a "development" webserver). As far as I can tell, this is something of a fast-moving target. What advice do people have? I'm using python 3, in case it makes a difference. Best wishes, N. -- https://mail.python.org/mailman/listinfo/python-list
Google API and Python 2
I started Python programming in the last few years and so I started with version 3 and 99% of my code is in version 3. Much of Google API Python code seems to be Python 2. I can convert the occasional file to version 3 with 2to3, but for an entire 3rd-party library, could it be as simple as using the find command (recursive) and iterating over the *py files in the download? -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
On Sun, 09 Feb 2014 04:13:50 -0800, Wesley wrote: > Hi guys, >Here is one question related to algorithm. > Details here: > > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx > always exist in pair. So, now, how to change the sequence to > a1,b1,...,an,bn, with time complexity as O(n) and space as O(1). Time complexity O(n) implies that you can iterate over the list at most a constant number of times. Space complexity O(1) implies that you can only use a small, constant amount of extra space, which means that you have to modify the input sequence in place. This is a kind of shuffle. Imagine you pull out all the spades ♠ and hearts ♡ from a deck of cards, and sort them individually: cards = ['A♠', '2♠', '3♠', '4♠', ... 'K♠', 'A♡', '2♡', '3♡', '4♡', ... 'K♡'] You want to move the cards so that you end up with the spades and hearts interleaved: cards = ['A♠', 'A♡', '2♠', '2♡', '3♠', '3♡', '4♠', '4♡', ... 'K♠', 'K♡'] This is called a "riffle shuffle" or "Faro shuffle", and there are two kinds, an in-shuffle and an out-shuffle, which differ in which card ends up on top. The obvious way to do it is to split the deck down the middle into two sets of cards, then riffle them together, one card from the left hand following by one card from the right (or visa versa): left = cards[:len(cards)//2] right = cards[len(cards)//2:] cards = [] for l, r in zip(left, right): cards.append(l) cards.append(r) but this doesn't use constant space, since it uses extra space proportional to N. Since this sounds like homework, I'm not going to tell you how to do this using only constant space, but it may help if you actually sit down with a set of cards, lay them out in order, and see how you might do it by hand. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python (?) webserver for WSGI
On Sunday, February 9, 2014 11:05:58 PM UTC+2, Nicholas wrote: > Dear List, > > > > What is the latest "best-practice" for deploying a python wsgi > application into production? > > For development, I've been using CherryPyWSGIServer which has been > working very well (and the code is small enough to actually ship with > my application). But I would like some way of deploying a server > listening on port 80 (and then dropping root privileges). > > I have looked at using gunicorn + ngnix, but that gives me 3 layers > that I need to set up: > > - my own application > - gunicorn > - ngnix Yes, but are you after simplicity of setup or reliability? If security is your concern - eventually you have to dive into routines of verifying settings auditing etc and spend week(s) if you have no solid prior experience in that field and even after that there is still a lot to learn. the interesting side of nginx is load balancing toward back end so you can distribute your back ends over multiple machines and have scalability for least effort, though seems you don't need due to low expected load. there is another popular choice nginx + uwsgi -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended python module for SQL database access?
On Mon, Feb 10, 2014 at 2:40 AM, Dennis Lee Bieber wrote: > Any opinion on Firebird? Just curiosity given how often the advice > seems to be "start with SQLite, avoid MySQL, end with PostgreSQL" No, because I've never used it. Has anyone here? What are its strengths and weaknesses? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: system wide mutex
On Mon, Feb 10, 2014 at 1:45 AM, Roy Smith wrote: > In article , > Skip Montanaro wrote: > >> As the author of lockfile, I can tell you it only implements advisory >> locking. All programs needing to access the locked resources must >> cooperate. > > This is true of all mutexes, no? > Not quite all; mandatory locks actually prevent other access. But they require support from whatever makes the resource available - most commonly, the file system - where cooperative locking doesn't. I've written a number of cooperative locking systems in the past (eg to protect a network resource, when the mounted file system didn't offer the sort of locking I needed), and they're usually the way to go when there's anything complicated going on. What, all mutexes? Yes, all mutexes! What, all? Well nearly all! -- with apologies to WS Gilbert, HMS Pinafore, and the Pirates of Penzance ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
On Mon, Feb 10, 2014 at 4:53 AM, Ethan Furman wrote: > Shouldn't that be: > > class Pig: > def fly(self): > "Soar gracefully through the air if a hot place is very cold." > if hell is frozen: > self.sprout_wings() > self.altitude += 10 > self.velocity += 25 > else: > self.splat() > > ;) The Python 'is' operator does not do what you think it does. If it did, 'hell is frozen' would mean that one could say 'war is frozen', which makes no sense. No, I think this calls for a LISP-style predicate: if frozenp(hell): ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Python (?) webserver for WSGI
On Sunday, 9 February 2014, Asaf Las > wrote: > On Sunday, February 9, 2014 11:05:58 PM UTC+2, Nicholas wrote: > > Dear List, > > > > > > > > What is the latest "best-practice" for deploying a python wsgi > > application into production? > > > > For development, I've been using CherryPyWSGIServer which has been > > working very well (and the code is small enough to actually ship with > > my application). But I would like some way of deploying a server > > listening on port 80 (and then dropping root privileges). > > > > I have looked at using gunicorn + ngnix, but that gives me 3 layers > > that I need to set up: > > > > - my own application > > - gunicorn > > - ngnix > > Yes, but are you after simplicity of setup or reliability? > If security is your concern - eventually you have to dive into > routines of verifying settings auditing etc and spend > week(s) if you have no solid prior experience in that field and even > after that there is still a lot to learn. > [snip] Yes, I managed a large apache installation for some years. I suppose that my hope was that in 2014 there might be some better, simpler way to run smaller web applications, especially with the tulip async stuff becoming part of the language. I don't think running a WSGI application to serve basic requests should NEED a lot of special setting up -- https://mail.python.org/mailman/listinfo/python-list
Re: imperative mood in docstrings
On Sun, 09 Feb 2014 16:05:59 +0400, bagrat lazaryan wrote:
> pep 257 -- docstring conventions, as well as a myriad of books and other
> resources, recommend documenting a function's or method's effect as a
> command ("do this", "return that"), not as a description ("does this",
> "returns that"). what's the logic behind this recommendation?
Consider a class with a procedural method, that is, a method that does
something:
class Duck:
def swim(self):
"""Flap feet in a rhythmic manner so as to gracefully move
through water.
"""
Here, we naturally write as if giving instructions to the duck, that is,
using the imperative mood. "Duck, swim."
>From there, it isn't a big step to using the same mood for functions:
def count(haystack, needle):
"""Return the number of needles in haystack."""
Here we are figuratively instructing the function, telling it what to do:
"Function, return the number of needles found in this haystack."
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
On Sun, 09 Feb 2014 10:05:02 -0500, Roy Smith wrote: > Is this a homework problem? and then (paraphrasing): > working code that solves the problem /headdesk -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Google Cloud Platform and GlassSolver Project
I am fully ready to invest in the Google Cloud Platform, and bring with me my very own idea: Glass Solver (Sometimes called GlaSolver). Long story short, this application for Google Glass will connect to the Cloud to retrieve God's Algorithm for the cube sitting in front of you by doing a series of scans of the cube. But, that (specifically) is not what I came here for. In order to have all these algorithms, I have to make them first. One important detail that is probably worth mentioning is the fact that this application will support no only 3x3s. It will also support 2x2s,4x4s,and 5x5s. The last 2 mentioned have not been done before. God's Number has never been found for the 4x4 or 5x5 cube. But thanks to Google and their Compute Platform, it is possible. I myself am relatively new to Python. My experience is in Java primarily. Again, long story even shorter, I am asking for a Python (2.7 please!) script for each cube. Thanks for reading this and possibly for your script! -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
In article <[email protected]>, Steven D'Aprano wrote: > On Sun, 09 Feb 2014 10:05:02 -0500, Roy Smith wrote: > > > Is this a homework problem? > > and then (paraphrasing): > > > working code that solves the problem > > /headdesk I gave him the benefit of the doubt. Also, as I look at my solution, I realize it doesn't really meet the O(1) space requirement. Understanding why is left as an exercise for the reader :-) -- https://mail.python.org/mailman/listinfo/python-list
[ANN] PyExt 0.6 Released!
PyExt is a set of nifty(and sometimes either overly hackish, overly dangerous, or overly both) extensions to Python. It has things like a switch statement, runtime module creation, function overloading(does NOT work with class methods...yet), and more! Links: PyPI: https://pypi.python.org/pypi/pyext GitHub: https://github.com/kirbyfan64/pyext -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated." -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
在 2014年2月9日星期日UTC+8下午11时48分17秒,Oscar Benjamin写道: > Please don't top-post. > > On Feb 9, 2014 2:40 PM, "Ni Wesley" wrote: > > > > > > Yes, with no new list, otherwise, space won't to be O(1) > > Did you read the link I posted: > > >> http://en.wikipedia.org/wiki/In-place_matrix_transposition > > > Oscar Sorry getting a network problem these two days. I am reading :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
> > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > > time complexity as O(n) and space as O(1). > > > > The two halves of the list are already sorted, yes? [Wesley] No, not sorted yet.. -- https://mail.python.org/mailman/listinfo/python-list
Re: Google Cloud Platform and GlassSolver Project
Also I should mention that I will credit whomever writes the scripts. I have contacted Google on their Compute Engine which would execute these scripts. I am await a reply! -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
[Wesley] This is not homework:-) And actually I am new to algorithm, so you guys can feel free to say anything you want -- https://mail.python.org/mailman/listinfo/python-list
Re: Google Cloud Platform and GlassSolver Project
[email protected] Wrote in message: > Also I should mention that I will credit whomever writes the scripts. I have > contacted Google on their Compute Engine which would execute these scripts. I > am await a reply! > It might help if you mention that you're talking about the Rubic cube, and supply an example of what you want in such a script. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Sort one sequence by O(n) in time and O(1) in space
Wesley Wrote in message: > >> > here is input sequence like a1,a2,...,an,b1,b2,...,bn ï¼the ax and bx >> > always exist in pair. So, now, how to change the sequence to >> > a1,b1,...,an,bn, with time complexity as O(n) and space as O(1). >> >> >> >> The two halves of the list are already sorted, yes? > > [Wesley] No, not sorted yet.. > -- > https://mail.python.org/mailman/listinfo/python-list > Then supply some example lists and show the result you want. So far, your description is thoroughly ambiguous. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.6 help with modules
On Feb 8, 2014, at 11:30 PM, Chris Angelico wrote:
I have one more question on this if you don’t mind. I’m a bit confused on how
it works this way without it being in seconds? I’ll answer below each step of
how it seems to work to me.
> How to do it from the small end up:
>
> time = int(raw_input("Enter number of seconds: "))
> seconds = time % 60
So here it takes say 100 and divides it by 60 to put in seconds and spits
out the remainder? 100 / 60 is approximately 1 with a remainder of
about 40, which would be the correct amount for seconds. From there I get a
little lost.
> time /= 60
Then we take the remainder (40) from above and divide that by 60? Already it’s
confusing me.
> minutes = time % 60
Are we still using the new number from above for time and dividing that by 60
and using the remainder for minutes?
> time /= 60
Then taking the remainder from the line above and so on and so on…?
> hours = time % 24
> time /= 24
> days = time % 7
> time /= 7
> weeks = time
> # Alternative way to format for display:
> print("%d weeks, %d days, %02d:%02d:%02d"%(weeks,days,hours,minutes,seconds))
>
Also, would it work the same way with smaller divisors the other way around
(from weeks - seconds)?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.6 help with modules
On Feb 8, 2014, at 11:30 PM, Chris Angelico wrote:
OH, I think I figured it out.
> time = int(raw_input("Enter number of seconds: “))
100
> seconds = time % 60
Remainder of 40 <- for seconds.
> time /= 60
Here you take 100/60 = 1 (which = time for the next line).
> minutes = time % 60
1/60 with a remainder of 46 <- minutes
> time /= 60
Then take 1/60 = 277 (which = time for the line below to use).
> hours = time % 24
Then we use 277/24 with a remainder of 13 <- hours
> time /= 24
Then it use 277/24……..
> days = time % 7
> time /= 7
> weeks = time
I guess I answered my own question and it looks like it wouldn’t matter if you
did it opposite from weeks to seconds.
Thanks again for all your help everyone!
Scott
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.6 help with modules
On Mon, Feb 10, 2014 at 3:17 PM, Scott W Dunning wrote:
> How to do it from the small end up:
>
> time = int(raw_input("Enter number of seconds: "))
> seconds = time % 60
>
> So here it takes say 100 and divides it by 60 to put in seconds and
> spits out the remainder? 100 / 60 is approximately 1 with a
> remainder of about 40, which would be the correct amount for seconds. From
> there I get a little lost.
>
> time /= 60
>
> Then we take the remainder (40) from above and divide that by 60? Already
> it’s confusing me.
The first part just spits out the remainder, without changing the
base. It'll set seconds to 40 (exactly, not about), but time is still
100. Then in the next line, we divide time by 60, which sets it to
that quotient (1). This is why it's probably clearer to use
divmod, which does both halves (quotient and remainder) at once.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.6 help with modules
On Mon, Feb 10, 2014 at 3:31 PM, Scott W Dunning wrote: > I guess I answered my own question and it looks like it wouldn’t matter if > you did it opposite from weeks to seconds. Yep, you've got it! Remember, you can always try things out in the interactive interpreter to see what's happening. Helps *hugely*. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
