Re: from scipy.linalg import _fblas ImportError: DLL load failed: The specified module could not be found.

2016-02-09 Thread Mark Lawrence

On 09/02/2016 04:22, Mike S via Python-list wrote:

I have Python 3.4.4 installed on Windows 7, also IPython, scipy, numpy,
statsmodels, and a lot of other modules, and am working through this
tutorial
http://www.analyticsvidhya.com/blog/2016/02/time-series-forecasting-codes-python/



[snip bulk of code and traceback]


 154
--> 155 from scipy.linalg import _fblas
 156 try:
 157 from scipy.linalg import _cblas

ImportError: DLL load failed: The specified module could not be found.

Do I read this correctly to mean that the very last import statement is
the one having the problem,

"from scipy.linalg import _fblas"

How do I troubleshoot this? I'm wondering if I have version conflict
between two modules.


Alomost certainly, hopefully this link will help.

http://stackoverflow.com/questions/21350153/error-importing-scipy-linalg-on-windows-python-3-3



Thanks,
Mike


No problem :)

--
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


[newbie] how to create log files

2016-02-09 Thread jenswaelkens
When I run my Python scripts from the command prompt in Linux, I can make 
visible all kinds of information I want to check by using print statements
e.g. print (top.winfo_width()), this is very useful when debugging.
However, the final version of my program won't be run from the command line, 
but by simply clicking on its icon on the desktop. I'd like to have
a log-file which gathers the output of all those print statements, so I still 
can check the same information I got before.
Can anyone here tell me how this is accomplished the best way?

thanks and kind regards,
Jens  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heap Implementation

2016-02-09 Thread Mark Lawrence

On 09/02/2016 04:25, Cem Karan wrote:


No problem, that's what I thought happened.  And you're right, I'm looking for 
a priority queue (not the only reason to use a heap, but a pretty important 
reason!)



I'm assuming I've missed the explanation, so what is the problem again 
with https://docs.python.org/3/library/queue.html#queue.PriorityQueue or 
even 
https://docs.python.org/3/library/asyncio-queue.html#asyncio.PriorityQueue ?


--
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: [newbie] how to create log files

2016-02-09 Thread marco . nawijn
Hello Jens,

Are you aware of Python's own logging facility? It is quite powerful
and flexible.

Python 2:
  https://docs.python.org/2/library/logging.html

Python 3:
  https://docs.python.org/3/library/logging.html

Marco
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] how to create log files

2016-02-09 Thread Mark Lawrence

On 09/02/2016 09:33, [email protected] wrote:

Hello and welcome.


When I run my Python scripts from the command prompt in Linux, I can make 
visible all kinds of information I want to check by using print statements
e.g. print (top.winfo_width()), this is very useful when debugging.
However, the final version of my program won't be run from the command line, 
but by simply clicking on its icon on the desktop. I'd like to have
a log-file which gathers the output of all those print statements, so I still 
can check the same information I got before.
Can anyone here tell me how this is accomplished the best way?

thanks and kind regards,
Jens



https://docs.python.org/3/library/logging.html

--
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


newbie. how can i solve this looping problem?

2016-02-09 Thread asdasdqeqe
http://pastebin.com/Khrm3gHq

for the code above, everytime it scraps off tweets and loads the next 13 
tweets, it'll re-run through the previous scrapped tweets before recording the 
new ones. I'm up to 700 over tweets and it'll keep re-running the previous 700 
before adding the final 13 to the list. I'm looking at a few thousand tweets so 
it'll slow down as the tweets get more and more. Any idea how i can stop it 
from going over the previous tweets and just add the last few?

how can i get this line 
elem = 
WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,lastTweetCss)))
 
to move on further in the code if it doesn't find anything after waiting for 10 
sec?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heap Implementation

2016-02-09 Thread Cem Karan

On Feb 9, 2016, at 4:40 AM, Mark Lawrence  wrote:

> On 09/02/2016 04:25, Cem Karan wrote:
>> 
>> No problem, that's what I thought happened.  And you're right, I'm looking 
>> for a priority queue (not the only reason to use a heap, but a pretty 
>> important reason!)
>> 
> 
> I'm assuming I've missed the explanation, so what is the problem again with 
> https://docs.python.org/3/library/queue.html#queue.PriorityQueue or even 
> https://docs.python.org/3/library/asyncio-queue.html#asyncio.PriorityQueue ?

Efficiently changing the the priority of items already in the queue/deleting 
items in the queue (not the first item).  This comes up a LOT in event-based 
simulators where it's easier to tentatively add an event knowing that you might 
need to delete it or change it later.

Thanks,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: coroutine, throw, yield, call-stack and exception handling

2016-02-09 Thread Veek. M
Ian Kelly wrote:

> On Mon, Feb 8, 2016 at 2:17 AM, Veek. M  wrote:
>> 
>> Exceptions can be raised inside a coroutine using the throw(
>>
>> Exceptions raised in this manner will originate at the currently
>> executing yield state-ment in the coroutine.A coroutine can elect to
>> catch exceptions and handle them as appropriate. It is not safe to
>> use throw() as an asynchronous signal to a coroutine—it should never
>> be invoked from a separate execution thread or in a signal handler.
>> 
>>
>> What does Beazley mean by this: 'will originate at the currently
>> executing yield state-ment in the coroutine'
>>
>> If he's throw'ing an exception surely it originates at the throw:
>>
>> def mycoroutine():
>>  while len(n) > 2:
>>n = (yield)
>>
>>  throw('RuntimeError' "die!")
> 
> The "throw" is not called from inside the coroutine. It's a method of
> the generator object, and it's used by the calling code. It's similar
> to calling the send method, except that instead of passing a value to
> be returned by the yield expression, it passes an exception to be
> raised inside the coroutine at the yield expression.
> 
> Example:
> 
> def mycoroutine():
>   n = 0
>   while True:
> try:
>   n = (yield n)
> except SomeException:
>   n = 42
> 
> coro = mycoroutine()
> coro.next()
> for i in range(100):
>   if i % 6 == 0:
> coro.send(i % 6)
>   else:
> coro.throw(SomeException())
> 
> 
>> Also this bit:
>> ***
>> If a coroutine returns values, some care is required if exceptions
>> raised with throw() are being handled. If you raise an exception in a
>> coroutine using throw(), the value passed to the next yield in the
>> coroutine will be returned as the result of throw(). If
>> you need this value and forget to save it, it will be lost.
>> ***
>>
>> def coroutine():
>>   while True:
>>line = (yield result)
>>
>>   throw(FooException)
>>
>> where is the question of a 'yield'? You'll exit the coroutine
>> straight away..
> 
> Taking my example from above, after SomeException is caught, the next
> value yielded inside the coroutine will be the return value of the
> coro.throw() call. This may be surprising if you're only expecting
> coro.send() and not coro.throw() to return yielded values.

Thanks, that made it abundantly clear :)
-- 
https://mail.python.org/mailman/listinfo/python-list


How to trap this error (comes from sqlite3)

2016-02-09 Thread cl
I have the following code snippet populating a wxPython grid with data
from a database. :-

#
#
# populate grid with data 
#
all = self.cur.execute("SELECT * from " + table + " ORDER by id ")
for row in all:
row_num = row[0]
cells = row[1:]
for col in range(len(cells)):
if cells[col] != None and cells[col] != "null":
xx = cells[col]
if not isinstance(xx, basestring):
xx = str(xx)
print("row: ",row_num, "col: ", col, "value: ", xx)

self.SetCellValue(row_num, col, xx)


It works fine until it hits an invalid character in one of the
columns.  The print is just a temporary diagnostic.

The output I get, when it hits an invalid character is:-

('row: ', 5814, 'col: ', 9, 'value: ', u'')
('row: ', 5814, 'col: ', 10, 'value: ', '10.5')
('row: ', 5814, 'col: ', 11, 'value: ', u'')
('row: ', 5814, 'col: ', 12, 'value: ', u' Fuel (with inter-tank tap open) 
is at about 10.5 - 11cm in the sight glass before setting out.')
('row: ', 6186, 'col: ', 0, 'value: ', '0')
Traceback (most recent call last):
  File "/home/chris/bin/pg.py", line 100, in 
grid = Grid(frame, dbCon, table)
  File "/home/chris/bin/pg.py", line 52, in __init__
self.SetCellValue(row_num, col, xx)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/grid.py", line 
2016, in SetCellValue
return _grid.Grid_SetCellValue(*args, **kwargs)
sqlite3.OperationalError: Could not decode to UTF-8 column 'dayno' with 
text '�'


It's absolutely right, there is a non-UTF character in the column.
However I don't want to have to clean up the data, it would take
rather a long time.  How can I trap the error and just put a Null or
zero in the datagrid?

Where do I put the try:/except: ?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to trap this error (comes from sqlite3)

2016-02-09 Thread Peter Otten
[email protected] wrote:

> I have the following code snippet populating a wxPython grid with data
> from a database. :-
> 
> #
> #
> # populate grid with data
> #
> all = self.cur.execute("SELECT * from " + table + " ORDER by id ")
> for row in all:
> row_num = row[0]
> cells = row[1:]
> for col in range(len(cells)):
> if cells[col] != None and cells[col] != "null":
> xx = cells[col]
> if not isinstance(xx, basestring):
> xx = str(xx)
> print("row: ",row_num, "col: ", col, "value: ", xx)
> 
> self.SetCellValue(row_num, col, xx)
> 
> 
> It works fine until it hits an invalid character in one of the
> columns.  The print is just a temporary diagnostic.
> 
> The output I get, when it hits an invalid character is:-
> 
> ('row: ', 5814, 'col: ', 9, 'value: ', u'')
> ('row: ', 5814, 'col: ', 10, 'value: ', '10.5')
> ('row: ', 5814, 'col: ', 11, 'value: ', u'')
> ('row: ', 5814, 'col: ', 12, 'value: ', u' Fuel (with inter-tank tap
> open) is at about 10.5 - 11cm in the sight glass before setting out.')
> ('row: ', 6186, 'col: ', 0, 'value: ', '0') Traceback (most recent
> call last):
>   File "/home/chris/bin/pg.py", line 100, in 
> grid = Grid(frame, dbCon, table)
>   File "/home/chris/bin/pg.py", line 52, in __init__
> self.SetCellValue(row_num, col, xx)
>   File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/grid.py", line
>   2016, in SetCellValue
> return _grid.Grid_SetCellValue(*args, **kwargs)
> sqlite3.OperationalError: Could not decode to UTF-8 column 'dayno'
> with text '�'
> 
> 
> It's absolutely right, there is a non-UTF character in the column.
> However I don't want to have to clean up the data, it would take
> rather a long time.  How can I trap the error and just put a Null or
> zero in the datagrid?
> 
> Where do I put the try:/except: ?

Handle the problem earlier on by setting a text_factory that ignores or 
replaces the offending bytes:

db = sqlite3.connect(...)
db.text_factory = lambda b: b.decode("utf-8", "replace")

https://docs.python.org/2.7/library/sqlite3.html#sqlite3.Connection.text_factory
https://docs.python.org/2/howto/unicode.html

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to trap this error (comes from sqlite3)

2016-02-09 Thread Mark Lawrence

On 09/02/2016 11:57, [email protected] wrote:

I have the following code snippet populating a wxPython grid with data
from a database. :-

 #
 #
 # populate grid with data
 #
 all = self.cur.execute("SELECT * from " + table + " ORDER by id ")
 for row in all:
 row_num = row[0]
 cells = row[1:]
 for col in range(len(cells)):
 if cells[col] != None and cells[col] != "null":
 xx = cells[col]
 if not isinstance(xx, basestring):
 xx = str(xx)
 print("row: ",row_num, "col: ", col, "value: ", xx)


The usual way of writing the above loop is:-

for cell in cells:
if cell != None and cell != "null":
xx = cell
if not isinstance(xx, basestring):
xx = str(xx)



 self.SetCellValue(row_num, col, xx)


It works fine until it hits an invalid character in one of the
columns.  The print is just a temporary diagnostic.

The output I get, when it hits an invalid character is:-

 ('row: ', 5814, 'col: ', 9, 'value: ', u'')
 ('row: ', 5814, 'col: ', 10, 'value: ', '10.5')
 ('row: ', 5814, 'col: ', 11, 'value: ', u'')
 ('row: ', 5814, 'col: ', 12, 'value: ', u' Fuel (with inter-tank tap open) 
is at about 10.5 - 11cm in the sight glass before setting out.')
 ('row: ', 6186, 'col: ', 0, 'value: ', '0')
 Traceback (most recent call last):
   File "/home/chris/bin/pg.py", line 100, in 
 grid = Grid(frame, dbCon, table)
   File "/home/chris/bin/pg.py", line 52, in __init__
 self.SetCellValue(row_num, col, xx)
   File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/grid.py", line 
2016, in SetCellValue
 return _grid.Grid_SetCellValue(*args, **kwargs)
 sqlite3.OperationalError: Could not decode to UTF-8 column 'dayno' with 
text '�'


It's absolutely right, there is a non-UTF character in the column.
However I don't want to have to clean up the data, it would take
rather a long time.  How can I trap the error and just put a Null or
zero in the datagrid?

Where do I put the try:/except: ?



The rule is always keep the try/except to the bare minimum hence.

try:
self.SetCellValue(row_num, col, xx)
except sqlite3.OperationalError:
doSomething()

--
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: newbie. how can i solve this looping problem?

2016-02-09 Thread Joel Goldstick
On Tue, Feb 9, 2016 at 5:49 AM,  wrote:

> http://pastebin.com/Khrm3gHq
>
> for the code above, everytime it scraps off tweets and loads the next 13
> tweets, it'll re-run through the previous scrapped tweets before recording
> the new ones. I'm up to 700 over tweets and it'll keep re-running the
> previous 700 before adding the final 13 to the list. I'm looking at a few
> thousand tweets so it'll slow down as the tweets get more and more. Any
> idea how i can stop it from going over the previous tweets and just add the
> last few?
>
> how can i get this line
> elem =
> WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,lastTweetCss)))
> to move on further in the code if it doesn't find anything after waiting
> for 10 sec?
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I can't answer your question, but to make it easier for someone who can,
put your code in your question, edit out all the code that has nothing to
do with your question, show what you get, and what you want.  If you get a
traceback, copy and paste it in the qeustion

Good luck

-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


First Program with Python!

2016-02-09 Thread anitagoyal571
Python is a very powerful high-level, object-oriented programming 
language.Python has a very easy-to-use and simple syntax, making it the perfect 
language for someone trying to learn computer programming for the first time. 
Python is an interpreted language. Interpreter is a program that converts the 
high-level program we write into low-level program that the computer 
understands. Click here to find the difference between interpreter and 
compiler. This tutorial is based on Python 3 and all the examples in this 
tutorial have been tested and verified in Python.

Start learning Python from basics to advance levels here...
https://goo.gl/hGzm6o
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Searching Sets (Lottery Results)

2016-02-09 Thread MrPink
On Monday, February 8, 2016 at 7:05:24 PM UTC-5, Chris Angelico wrote:
> On Tue, Feb 9, 2016 at 8:45 AM, MrPink wrote:
> > I load the lottery drawings into memory for searching with the following 
> > code although, it is incomplete.  I am stuck and need some guidance.
> >
> > The set datatype seems to be the best for searching, but how best can I 
> > implement it?
> >
> > And I want the results to highlight the numbers that were matched.  For 
> > example, if the white balls in the drawing are:
> > "42 15 06 05 29"
> >
> > AND the numbers on the lottery ticket are:
> > "06 15 32 42 56"
> >
> > THEN the display might look like:
> > "06* 15* 32 42* 56"
> >
> > WHERE * signifies a match.
> >
> 
> This suggests that there is an order to the numbers on your ticket
> (you want to print them out in the same order), but not to the winning
> numbers, which are simply a set. The easiest way to handle that would
> be to iterate over your numbers, asking "if number in
> winning_numbers:", and printing out a "match" marker if it is or a
> "non-match" marker if it isn't.
> 
> ChrisA

Thanks Chris.  Very good point.  I was just too deep in the weeds to see that 
simple solution.  I was overthinking it.  ;-)

Sincerely,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbie. how can i solve this looping problem?

2016-02-09 Thread asdasdqeqe
http://pastebin.com/uQSW5iwZ

here's the part of the code which I would like to change. I don't know how to 
get the following line to not "Timeout" and instead continue onwards to 
printTweet(driver)

elem = 
WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,lastTweetCss)))
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heap Implementation

2016-02-09 Thread Mark Lawrence

On 09/02/2016 11:44, Cem Karan wrote:


On Feb 9, 2016, at 4:40 AM, Mark Lawrence  wrote:


On 09/02/2016 04:25, Cem Karan wrote:


No problem, that's what I thought happened.  And you're right, I'm looking for 
a priority queue (not the only reason to use a heap, but a pretty important 
reason!)



I'm assuming I've missed the explanation, so what is the problem again with 
https://docs.python.org/3/library/queue.html#queue.PriorityQueue or even 
https://docs.python.org/3/library/asyncio-queue.html#asyncio.PriorityQueue ?


Efficiently changing the the priority of items already in the queue/deleting 
items in the queue (not the first item).  This comes up a LOT in event-based 
simulators where it's easier to tentatively add an event knowing that you might 
need to delete it or change it later.

Thanks,
Cem Karan



Thanks for that, but from the sounds of it sooner you than me :)

--
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: How to trap this error (comes from sqlite3)

2016-02-09 Thread cl
Peter Otten <[email protected]> wrote:
> [email protected] wrote:
> 
> > It's absolutely right, there is a non-UTF character in the column.
> > However I don't want to have to clean up the data, it would take
> > rather a long time.  How can I trap the error and just put a Null or
> > zero in the datagrid?
> > 
> > Where do I put the try:/except: ?
> 
> Handle the problem earlier on by setting a text_factory that ignores or 
> replaces the offending bytes:
> 
> db = sqlite3.connect(...)
> db.text_factory = lambda b: b.decode("utf-8", "replace")
> 
> https://docs.python.org/2.7/library/sqlite3.html#sqlite3.Connection.text_factory
> https://docs.python.org/2/howto/unicode.html
> 
Brilliant, thank you, works perfectly and (IMHO) is about the neatest
possible solution.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


ImportError: cannot import name 'RAND_egd'

2016-02-09 Thread shaunak . bangale
Hi,

I am trying to run a 60 lines Python code which is running on a mac machine but 
on windows machine, I am getting this error when I run on it on shell(open file 
and run module). I have Python 3.5 installed.

   from _ssl import RAND_status, RAND_egd, RAND_add
ImportError: cannot import name 'RAND_egd'

Form forums, I found that it is a common error but could not find a good 
solution that will work for me.

One of the ways was to create scripts folder and putting easy_install.exe and 
then running easy_install pip but that gave me sytnax error.

Please advise. Thanks in advance.

Regards
Shaunak
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set Operations on Dicts

2016-02-09 Thread Ian Kelly
On Tue, Feb 9, 2016 at 12:21 AM, Grobu  wrote:
> On 08/02/16 17:12, Ian Kelly wrote:
>
>> dict does already expose set-like views. How about:
>>
>> {k: d[k] for k in d.keys() & s}  # d & s
>> {k: d[k] for k in d.keys() - s}  # d - s
>>
> Interesting. But seemingly only applies to Python 3.

Substitute d.viewkeys() for d.keys() in Python 2.7.
-- 
https://mail.python.org/mailman/listinfo/python-list


Cygwin and Python3

2016-02-09 Thread Fillmore


Hi, I am having a hard time making my Cygwin run Python 3.5 (or Python 2.7 for 
that matter).
The command will hang and nothing happens.

A cursory search on the net reveals many possibilities, which might mean a lot
of trial and error, which I would very much like to avoid.

Any suggestions on how I can get cygwin and Python3.5 to play together like 
brother and sister?

thanks
--
https://mail.python.org/mailman/listinfo/python-list


Re: Cygwin and Python3

2016-02-09 Thread alvin . hacopian
On Tuesday, February 9, 2016 at 8:41:43 AM UTC-8, Fillmore wrote:
> Hi, I am having a hard time making my Cygwin run Python 3.5 (or Python 2.7 
> for that matter).
> The command will hang and nothing happens.
> 
> A cursory search on the net reveals many possibilities, which might mean a lot
> of trial and error, which I would very much like to avoid.
> 
> Any suggestions on how I can get cygwin and Python3.5 to play together like 
> brother and sister?
> 
> thanks

Please see bellow:
$ whereis python
python: /usr/bin/python /usr/bin/python2.7-config /usr/bin/python3.2 
/usr/bin/python3.2m-config /usr/lib/python2.6 /usr/lib/python2.7 
/usr/lib/python3.2 /usr/local/bin/python /usr/local/bin/python2.7 
/usr/local/lib/python2.7 /usr/include/python2.7 /usr/include/python3.2m 
/usr/share/man/man1/python.1.gz

$ echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program
 Files (x86)/Vim/vim73:/cygdrive/c/Program Files/WIDCOMM/Bluetooth 
Software:/cygdrive/c/Program Files/WIDCOMM/Bluetooth 
Software/syswow64:/cygdrive/c/Program Files 
(x86)/Skype/Phone:/cygdrive/c/opscode/chef/bin:/cygdrive/c/opscode/chef/embedded/bin:/opt/apache2/bin:/cygdrive/c/Program
 Files (x86)/QuickTime/QTSystem:/usr/sbin:/usr/lib/lapack

$ ls -l /usr/bin/python
rm /usr/bin/python

$ ln -s /usr/bin/python /usr/bin/python3.2m.exe

$ /usr/bin/python --version
Python 3.2.5

$  pydoc modules
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cygwin and Python3

2016-02-09 Thread Fillmore

On 2/9/2016 2:29 PM, [email protected] wrote:




$ ls -l /usr/bin/python
rm /usr/bin/python

$ ln -s /usr/bin/python /usr/bin/python3.2m.exe

$ /usr/bin/python --version
Python 3.2.5

$  pydoc modules



Still no luck (:

 ~
$ python --version
Python 3.5.1

 ~
$ python
(..hangs indefinitely)
^C

 ~
$ pydoc modules
-bash: pydoc: command not found

 ~
$ echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/Python27:/cygdrive/c/
Python27/Scripts:/cygdrive/c/Windows/system32:/cygdrive/
c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/
c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/
c/Program Files (x86)/Common Files/Roxio Shared/OEM/
DLLShared:/cygdrive/c/Program Files (x86)/Common Files/
Roxio Shared/OEM/DLLShared:/cygdrive/c/Program
 Files (x86)/Common Files/Roxio Shared/OEM/12.0/
DLLShared:/cygdrive/c/Program Files (x86)/Roxio/OEM/
AudioCore:/cygdrive/c/unxutils/bin:/cygdrive/c/unxutils
/usr/local/wbin:/cygdrive/c/strawberry/c/bin:/cygdrive/
c/strawberry/perl/site/bin:/cygdrive/c/strawberry/
perl/bin:/cygdrive/c/Program Files/Intel/WiFi/bin:/
cygdrive/c/Program Files/Common Files/Intel/
WirelessCommon:/cygdrive/c/Users/user/AppData/Local/
Programs/Python/Python35/Scripts:/cygdrive/c/Users/
user/AppData/Local/Programs/Python/Python35:%APPDATA%
/Python/Scripts:/cygdrive/c/Program Files/Intel/WiFi/
bin:/cygdrive/c/Program Files/Common Files/Intel/
WirelessCommon


--
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: cannot import name 'RAND_egd'

2016-02-09 Thread Ian Kelly
On Tue, Feb 9, 2016 at 7:55 AM,   wrote:
> Hi,
>
> I am trying to run a 60 lines Python code which is running on a mac machine 
> but on windows machine, I am getting this error when I run on it on 
> shell(open file and run module). I have Python 3.5 installed.
>
>from _ssl import RAND_status, RAND_egd, RAND_add
> ImportError: cannot import name 'RAND_egd'

Why are you importing these directly from the "_ssl" C module and not
from the "ssl" wrapper module? Anything that starts with an _ should
be considered a private implementation detail and shouldn't be relied
upon.

> Form forums, I found that it is a common error but could not find a good 
> solution that will work for me.
>
> One of the ways was to create scripts folder and putting easy_install.exe and 
> then running easy_install pip but that gave me sytnax error.
>
> Please advise. Thanks in advance.

The ssl module in the standard library has this:

try:
from _ssl import RAND_egd
except ImportError:
# LibreSSL does not provide RAND_egd
pass

So it looks like you cannot depend on ssl.RAND_egd to be present.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cygwin and Python3

2016-02-09 Thread alvin . hacopian
On Tuesday, February 9, 2016 at 12:20:06 PM UTC-8, Fillmore wrote:
> On 2/9/2016 2:29 PM, [email protected] wrote:
> 
> 
> >
> > $ ls -l /usr/bin/python
> > rm /usr/bin/python
> >
> > $ ln -s /usr/bin/python /usr/bin/python3.2m.exe
> >
> > $ /usr/bin/python --version
> > Python 3.2.5
> >
> > $  pydoc modules
> >
> 
> Still no luck (:
> 
>   ~
> $ python --version
> Python 3.5.1
> 
>   ~
> $ python
> (..hangs indefinitely)
> ^C
> 
>   ~
> $ pydoc modules
> -bash: pydoc: command not found
> 
>   ~
> $ echo $PATH
> /usr/local/bin:/usr/bin:/cygdrive/c/Python27:/cygdrive/c/
> Python27/Scripts:/cygdrive/c/Windows/system32:/cygdrive/
> c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/
> c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/
> c/Program Files (x86)/Common Files/Roxio Shared/OEM/
> DLLShared:/cygdrive/c/Program Files (x86)/Common Files/
> Roxio Shared/OEM/DLLShared:/cygdrive/c/Program
>   Files (x86)/Common Files/Roxio Shared/OEM/12.0/
> DLLShared:/cygdrive/c/Program Files (x86)/Roxio/OEM/
> AudioCore:/cygdrive/c/unxutils/bin:/cygdrive/c/unxutils
> /usr/local/wbin:/cygdrive/c/strawberry/c/bin:/cygdrive/
> c/strawberry/perl/site/bin:/cygdrive/c/strawberry/
> perl/bin:/cygdrive/c/Program Files/Intel/WiFi/bin:/
> cygdrive/c/Program Files/Common Files/Intel/
> WirelessCommon:/cygdrive/c/Users/user/AppData/Local/
> Programs/Python/Python35/Scripts:/cygdrive/c/Users/
> user/AppData/Local/Programs/Python/Python35:%APPDATA%
> /Python/Scripts:/cygdrive/c/Program Files/Intel/WiFi/
> bin:/cygdrive/c/Program Files/Common Files/Intel/
> WirelessCommon

When you run the cygwin installer you have the option of installing 2.7 and 
3.2.5, by default it will install 2.7 and 3.2 together. After running the 
installer run whereis python and use the alternatives to change it or use 
python3 instead of python #!/usr/bin/python3

Hope this helps.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cygwin and Python3

2016-02-09 Thread Fillmore

On 2/9/2016 3:30 PM, [email protected] wrote:



When you run the cygwin installer you have the option of installing 2.7

> and 3.2.5, by default it will install 2.7 and 3.2 together.
> After running the installer run whereis python and use the alternatives
> to change it or use python3 instead of python #!/usr/bin/python3


Hope this helps.



I see. I was trying to do it the Perl way. I simply linked the 
strawberry perl.exe from cygwin environemnt and it replaced the built in 
perl that sucked.

OK. Backtrack. I'll try with a purely cygwin solution...

Thank you


--
https://mail.python.org/mailman/listinfo/python-list


Re: Cygwin and Python3

2016-02-09 Thread Fillmore

On 2/9/2016 4:47 PM, Fillmore wrote:

On 2/9/2016 3:30 PM, [email protected] wrote:



When you run the cygwin installer you have the option of installing 2.7

 > and 3.2.5, by default it will install 2.7 and 3.2 together.
 > After running the installer run whereis python and use the alternatives
 > to change it or use python3 instead of python #!/usr/bin/python3


Hope this helps.



I see. I was trying to do it the Perl way. I simply linked the
strawberry perl.exe from cygwin environemnt and it replaced the built in
perl that sucked.
OK. Backtrack. I'll try with a purely cygwin solution...

Thank you




$ python --version
Python 2.7.10

$ python3 --version
Python 3.4.3

Thank you, Alvin

--
https://mail.python.org/mailman/listinfo/python-list


Importing two modules of same name

2016-02-09 Thread Tim Johnson
Before proceding, let me state that this is to satisfy my
curiousity, not to solve any problem I am having.

Scenario :
Web application developed at /some/dir/sites/flask/

If I have a package - let us call it app and in my
/some/dir/sites/flask/app/__init__.py is the following:

from config import config

imports the config dictionary from  /some/dir/sites/flask/config.py

(the real-case scenario is M. Grinberg's tutorial on Flask).

What if I wanted to add a module in the app package and call it from
__init__.py

That entails having two modules name config
one at /some/dir/sites/flask/config.py
and the other at /some/dir/sites/flask/app/config.py

What would be the proper way to do this? (If proper at all :)) I
realize that it may not be best practices. And is a practice that I
avoided in the past.

FYI: 
Platform - python 2.7 on Ubuntu 14.04. 
Experience: long-time python CGI programmer before retiring about 3
years ago.

Thanks
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from scipy.linalg import _fblas ImportError: DLL load failed: The specified module could not be found.

2016-02-09 Thread Mike S via Python-list

On 2/9/2016 1:33 AM, Mark Lawrence wrote:

On 09/02/2016 04:22, Mike S via Python-list wrote:

I have Python 3.4.4 installed on Windows 7, also IPython, scipy, numpy,
statsmodels, and a lot of other modules, and am working through this
tutorial
http://www.analyticsvidhya.com/blog/2016/02/time-series-forecasting-codes-python/


[snip bulk of code and traceback]


 154
--> 155 from scipy.linalg import _fblas
 156 try:
 157 from scipy.linalg import _cblas
ImportError: DLL load failed: The specified module could not be found.
Do I read this correctly to mean that the very last import statement is
the one having the problem,
"from scipy.linalg import _fblas"
How do I troubleshoot this? I'm wondering if I have version conflict
between two modules.


Alomost certainly, hopefully this link will help.
http://stackoverflow.com/questions/21350153/error-importing-scipy-linalg-on-windows-python-3-3


Thanks,
Mike


No problem :)


Mark,

I uninstalled scipy, numpy and pandas, then installed this version
  scipy-0.15.1-win32-superpack-python3.4
I had previously installed this version
  scipy-0.16.1-win32-superpack-python3.4
That solved the conflict, you have great search skills, I tried but 
didn't find a resolution.


Thanks Very Much!
Mike

--
https://mail.python.org/mailman/listinfo/python-list


Re: Importing two modules of same name

2016-02-09 Thread Carl Meyer
Hi Tim,

On 02/09/2016 04:23 PM, Tim Johnson wrote:
> Before proceding, let me state that this is to satisfy my
> curiousity, not to solve any problem I am having.
> 
> Scenario :
> Web application developed at /some/dir/sites/flask/
> 
> If I have a package - let us call it app and in my
> /some/dir/sites/flask/app/__init__.py is the following:
> 
> from config import config
> 
> imports the config dictionary from  /some/dir/sites/flask/config.py
> 
> (the real-case scenario is M. Grinberg's tutorial on Flask).
> 
> What if I wanted to add a module in the app package and call it from
> __init__.py
> 
> That entails having two modules name config
> one at /some/dir/sites/flask/config.py
> and the other at /some/dir/sites/flask/app/config.py
> 
> What would be the proper way to do this? (If proper at all :)) I
> realize that it may not be best practices. And is a practice that I
> avoided in the past.

The proper way to do this in Python 2.7 is to place `from __future__
import absolute_import` at the top of flask/app/__init__.py (maybe best
at the top of every Python file in your project, to keep the behavior
consistent). Once you have that future-import, `import config` will
always import the top-level config.py. To import the "local" config.py,
you'd either `from . import config` or `import app.config`.

Python 3 behaves this way without the need for a future-import.

If you omit the future-import in Python 2.7, `import config` will import
the neighboring app/config.py by default, and there is no way to import
the top-level config.py.

Carl



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's import situation has driven me to the brink of imsanity

2016-02-09 Thread Oscar Benjamin
On 8 February 2016 at 00:38,   wrote:
> Running python setup.py develop doesn't work, it gives me this error: error: 
> invalid command 'develop'

This is presumably because your setup.py script uses distutils rather
than setuptools: distutils doesn't have the develop command.

> Running pip install -e . does work.

That's because pip "injects setuptools" so that when you import
distutils in your setup.py your actually importing a monkey-patched
setuptools. You may as well import setuptools in your setup.py but
either way the recommended invocation is "pip install -e .".

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heap Implementation

2016-02-09 Thread Cem Karan

On Feb 9, 2016, at 9:27 AM, Mark Lawrence  wrote:

> On 09/02/2016 11:44, Cem Karan wrote:
>> 
>> On Feb 9, 2016, at 4:40 AM, Mark Lawrence  wrote:
>> 
>>> On 09/02/2016 04:25, Cem Karan wrote:
 
 No problem, that's what I thought happened.  And you're right, I'm looking 
 for a priority queue (not the only reason to use a heap, but a pretty 
 important reason!)
 
>>> 
>>> I'm assuming I've missed the explanation, so what is the problem again with 
>>> https://docs.python.org/3/library/queue.html#queue.PriorityQueue or even 
>>> https://docs.python.org/3/library/asyncio-queue.html#asyncio.PriorityQueue ?
>> 
>> Efficiently changing the the priority of items already in the queue/deleting 
>> items in the queue (not the first item).  This comes up a LOT in event-based 
>> simulators where it's easier to tentatively add an event knowing that you 
>> might need to delete it or change it later.
>> 
>> Thanks,
>> Cem Karan
>> 
> 
> Thanks for that, but from the sounds of it sooner you than me :)

Eh, its not too bad once you figure out how to do it.  It's easier in C though; 
you can use pointer tricks that let you find the element in constant time, and 
then removal will involve figuring out how to fix up your heap after you've 
removed the element.

Thanks,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Importing two modules of same name

2016-02-09 Thread Tim Johnson
* Carl Meyer  [160209 15:28]:
> Hi Tim,
<...> 
> The proper way to do this in Python 2.7 is to place `from __future__
> import absolute_import` at the top of flask/app/__init__.py (maybe best
> at the top of every Python file in your project, to keep the behavior
> consistent). Once you have that future-import, `import config` will
> always import the top-level config.py. To import the "local" config.py,
> you'd either `from . import config` or `import app.config`.
> 
> Python 3 behaves this way without the need for a future-import.
> 
> If you omit the future-import in Python 2.7, `import config` will import
> the neighboring app/config.py by default, and there is no way to import
> the top-level config.py.

  Thanks for setting me straight Carl.
  I'm including the full package constructor (app/__init__.py) code
  for other's edification and further comment (if deemed necessary).
  Some commented annotation added
##
from __future__ import absolute_import
from flask import Flask
from flask.ext.bootstrap import Bootstrap
from flask.ext.mail import Mail
from flask.ext.moment import Moment
from flask.ext.sqlalchemy import SQLAlchemy

# Import top-level config
from config import config

# Import same-level config avoiding name collision
from . import config as cfg

bootstrap = Bootstrap()
mail = Mail()
moment = Moment()
db = SQLAlchemy()


def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)

bootstrap.init_app(app)
mail.init_app(app)
moment.init_app(app)
db.init_app(app)

from .main import main as main_blueprint
app.register_blueprint(main_blueprint)

return app
  
Cheers  
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com
-- 
https://mail.python.org/mailman/listinfo/python-list


There has to be a better way to split this string!

2016-02-09 Thread Anthony Papillion
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Hello Everyone,

I am using datetime.now() to create a unique version of a filename.
When the final file is named, it will look something like:

myfile-2015-02-09-19-08-45-4223

Notice I'm replacing all of the "."'s, " "'s, and ":"'s returned by
datetime.now() with "-"'s. I'm doing that using the following code but
it's freaking ugly and I KNOW there is a better way to do it. I just
can't seem to think of it right now. Can anyone help? What is the
"right", or at least, less ugly, way to do this task?

Here is the code I'm using:


unprocessed_tag = str(datetime.datetime.now())
removed_spaces = unprocessed_tag.split(" ")
intermediate_string = removed_spaces[0] + "-" + removed_spaces[1]
removed_colons = intermediate_string.split(":")
intermediate_string = removed_colons[0] + "-" + removed_colons[1]
+ "-" + removed_colons[2]
removed_dots = intermediate_string.split(".")
final_string = removed.dots[0] + "-" + removed_dots[1]

return final_string

Thanks!
Anthony

-BEGIN PGP SIGNATURE-

iQIcBAEBCgAGBQJWupG0AAoJEAKK33RTsEsVVJEQAKZEk5jolpxa4plDvW6rY9ux
YdXHxtBa3emLprVMJTAg6+NJLZaeBjulttWv2Vy1y2tE8j1prLqHVtzITdX5kVG5
z0VUZgLRYi9Ocfk5vz4lGsWEWwRtkUQrpodbXqCArerUkBqHEW/Bgs2PGq9FGbNP
6QCWLsNr1APkEl5q8P3QCM7x1z0nsQKsbVMdvNjfi2kzsvDIm6lXgl9uUFxOFesp
fUkuiLFHFpbIRnnMke2mLahXWyN14QNmw6OOkqG963gOjecfC+2dNozAOSf42ul+
s2p9h3BiwijMvU/nvc/6jR3uFmoE3dIcGWsyYFNPWnPvrHUy0qHIgcavWDEo3+cw
J+qOYSX3XlTIrGc5ZJKdJWs6FH7d1+WZ4GndSj316LAKq0XN46rq/ppJksStpUwU
I7Gmk9mAnRt9uZy25xsx93jY8IiiOKDmI1cTclo/UKAYvQk8ib/allLnVZrssmsc
2hgugwBe6R966wavdrYl/yt1VlfwRdImRUL6pTNnCDMYYcJS0F7ATJ/dWV9iRD0h
PiIiB6zB61EyKw1djBRQ0F8XqxNZK0qR0UMR5hPWJcHRp3y94bgl2tI0/aMXmFW+
jiwQ4ecNgqb9k2C6iok+9OXJ3YoqToVbXFS7/svXpS88giksS+Re+5RChxZGSWSd
gXhYvKEHs+2l3Vuyhdsr
=8uK+
-END PGP SIGNATURE-

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heap Implementation

2016-02-09 Thread srinivas devaki
On Feb 10, 2016 6:11 AM, "Cem Karan"  wrote:
>
> Eh, its not too bad once you figure out how to do it.  It's easier in C
though; you can use pointer tricks that let you find the element in
constant time, and then removal will involve figuring out how to fix up
your heap after you've removed the element.
>

If you can do it with C pointers then you can do it with python's
references/mutable objects. :)
in case of immutable objects, use a light mutable wrapper or better use
list for performance.

Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: There has to be a better way to split this string!

2016-02-09 Thread Chris Angelico
On Wed, Feb 10, 2016 at 12:26 PM, Anthony Papillion
 wrote:
> I am using datetime.now() to create a unique version of a filename.

First off, be aware that this won't make a unique file name. But if
you're okay with that (deal with collisions somehow), then sure.

> When the final file is named, it will look something like:
>
> myfile-2015-02-09-19-08-45-4223
>
> Notice I'm replacing all of the "."'s, " "'s, and ":"'s returned by
> datetime.now() with "-"'s. I'm doing that using the following code but
> it's freaking ugly and I KNOW there is a better way to do it. I just
> can't seem to think of it right now. Can anyone help? What is the
> "right", or at least, less ugly, way to do this task?

Instead of using str(), use strftime():

>>> now = datetime.datetime.now()
>>> str(now)
'2016-02-10 12:34:26.377701'
>>> now.strftime("%Y-%m-%d-%H-%M-%S-%f")
'2016-02-10-12-34-26-377701'

You could instead use some other format string if you like. Here's your options:

https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SOLVED] There has to be a better way to split this string!

2016-02-09 Thread Anthony Papillion
On 02/09/2016 07:26 PM, Anthony Papillion wrote:
> Hello Everyone,
> 
> I am using datetime.now() to create a unique version of a filename.
> When the final file is named, it will look something like:
> 
> myfile-2015-02-09-19-08-45-4223
> 
> Notice I'm replacing all of the "."'s, " "'s, and ":"'s returned by
> datetime.now() with "-"'s. I'm doing that using the following code but
> it's freaking ugly and I KNOW there is a better way to do it. I just
> can't seem to think of it right now. Can anyone help? What is the
> "right", or at least, less ugly, way to do this task?

Found the solution in strftime(). Exactly what I was looking for.



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: There has to be a better way to split this string!

2016-02-09 Thread Oscar Benjamin
On 10 February 2016 at 01:26, Anthony Papillion  wrote:
> I am using datetime.now() to create a unique version of a filename.
> When the final file is named, it will look something like:
>
> myfile-2015-02-09-19-08-45-4223
>
> Notice I'm replacing all of the "."'s, " "'s, and ":"'s returned by
> datetime.now() with "-"'s. I'm doing that using the following code but
> it's freaking ugly and I KNOW there is a better way to do it. I just
> can't seem to think of it right now. Can anyone help? What is the
> "right", or at least, less ugly, way to do this task?
>
> Here is the code I'm using:
>
>
> unprocessed_tag = str(datetime.datetime.now())
> removed_spaces = unprocessed_tag.split(" ")
> intermediate_string = removed_spaces[0] + "-" + removed_spaces[1]
> removed_colons = intermediate_string.split(":")
> intermediate_string = removed_colons[0] + "-" + removed_colons[1]
> + "-" + removed_colons[2]
> removed_dots = intermediate_string.split(".")
> final_string = removed.dots[0] + "-" + removed_dots[1]
>
> return final_string

Chris' suggestion to use strftime is better but assuming you really
needed to work with the default string then there are easier ways
e.g.:

>>> from datetime import datetime
>>> str(datetime.now()).translate(str.maketrans(': .', '---'))
'2016-02-10-01-44-54-244789'

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SOLVED] There has to be a better way to split this string!

2016-02-09 Thread Ben Finney
Anthony Papillion  writes:

> On 02/09/2016 07:26 PM, Anthony Papillion wrote:
> > I am using datetime.now() to create a unique version of a filename.
> > […]
>
> Found the solution in strftime(). Exactly what I was looking for.

For the task of making a unique filename, you should also consider the
‘tempfile’ module in the standard library.

-- 
 \   “I distrust those people who know so well what God wants them |
  `\to do to their fellows, because it always coincides with their |
_o__)  own desires.” —Susan Brownell Anthony, 1896 |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: There has to be a better way to split this string!

2016-02-09 Thread srinivas devaki
On Feb 10, 2016 6:56 AM, "Anthony Papillion" 
wrote:
>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
>
> Hello Everyone,
>
> I am using datetime.now() to create a unique version of a filename.
> When the final file is named, it will look something like:
>
> myfile-2015-02-09-19-08-45-4223
>

You can easily do this(retrieving the tokens) using re module.

In [33]: mat =
re.search(r'(\S+)-(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{4})',
'myfi-le-2015-02-09-19-08-45-4223')

In [34]: mat

Out[34]: <_sre.SRE_Match object; span=(0, 32),
match='myfi-le-2015-02-09-19-08-45-4223'>

In [35]: mat.groups() Out[35]: ('myfi-le', '2015', '02', '09', '19', '08',
'45', '4223')

In [36]: mat =
re.search(r'(\S+)-(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{4})',
'myfile-2015-02-09-19-08-45-4223')
In [37]: mat

Out[37]: <_sre.SRE_Match object; span=(0, 31),
match='myfile-2015-02-09-19-08-45-4223'> In [38]: mat.groups()

Out[38]: ('myfile', '2015', '02', '09', '19', '08', '45', '4223')

if you don't want fiddle with regex you can use parse module(
https://github.com/r1chardj0n3s/parse). but why use an external library
when stdlib already provides it? :)

Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SOLVED] There has to be a better way to split this string!

2016-02-09 Thread Anthony Papillion
On 02/09/2016 07:47 PM, Ben Finney wrote:
> Anthony Papillion  writes:
> 
>> On 02/09/2016 07:26 PM, Anthony Papillion wrote:
>>> I am using datetime.now() to create a unique version of a filename.
>>> […]
>>
>> Found the solution in strftime(). Exactly what I was looking for.
> 
> For the task of making a unique filename, you should also consider the
> ‘tempfile’ module in the standard library.

I looked at tempfile. Unfortunately, the filename has to be both
'unique' and 'identifiable' to the original. So if I am using mydog.jpg
as the source and I am adding something unique to it, it has to still
have mydog.jpg in the filename. Tempfile, I think, doesn't allow an easy
way to do that. So I'm just adding the exact date and time which is
unique enough for my purposes.

Thanks for the pointer though.

Anthony


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: There has to be a better way to split this string!

2016-02-09 Thread Tim Chase
On 2016-02-09 19:26, Anthony Papillion wrote:
> myfile-2015-02-09-19-08-45-4223
> 
> Notice I'm replacing all of the "."'s, " "'s, and ":"'s returned by
> datetime.now() with "-"'s. I'm doing that using the following code
> but it's freaking ugly and I KNOW there is a better way to do it. I
> just can't seem to think of it right now. Can anyone help? What is
> the "right", or at least, less ugly, way to do this task?
> 
> unprocessed_tag = str(datetime.datetime.now())
> removed_spaces = unprocessed_tag.split(" ")
> intermediate_string = removed_spaces[0] + "-" +
> removed_spaces[1] removed_colons = intermediate_string.split(":")
> intermediate_string = removed_colons[0] + "-" +
> removed_colons[1]
> + "-" + removed_colons[2]
> removed_dots = intermediate_string.split(".")
> final_string = removed.dots[0] + "-" + removed_dots[1]

Why not format it the way you want to begin with?

  >>> datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f")
  '2016-02-09-19-38-17-972532'

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SOLVED] There has to be a better way to split this string!

2016-02-09 Thread Chris Kaynor
On Tue, Feb 9, 2016 at 5:58 PM, Anthony Papillion 
wrote:
>
> On 02/09/2016 07:47 PM, Ben Finney wrote:
> > Anthony Papillion  writes:
> >
> >> On 02/09/2016 07:26 PM, Anthony Papillion wrote:
> >>> I am using datetime.now() to create a unique version of a filename.
> >>> […]
> >>
> >> Found the solution in strftime(). Exactly what I was looking for.
> >
> > For the task of making a unique filename, you should also consider the
> > ‘tempfile’ module in the standard library.
>
> I looked at tempfile. Unfortunately, the filename has to be both
> 'unique' and 'identifiable' to the original. So if I am using mydog.jpg
> as the source and I am adding something unique to it, it has to still
> have mydog.jpg in the filename. Tempfile, I think, doesn't allow an easy
> way to do that. So I'm just adding the exact date and time which is
> unique enough for my purposes.

Actually, it doe (untested, but I've used the feature in projects):

tempfile.TemporaryFile(prefix="mydog", suffix=".jpg")

Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: There has to be a better way to split this string!

2016-02-09 Thread srinivas devaki
On Feb 10, 2016 7:23 AM, "srinivas devaki" 
wrote:
>
>
> On Feb 10, 2016 6:56 AM, "Anthony Papillion" 
wrote:
> >
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA512
> >
> > Hello Everyone,
> >
> > I am using datetime.now() to create a unique version of a filename.
> > When the final file is named, it will look something like:
> >
> > myfile-2015-02-09-19-08-45-4223
> >
>
> You can easily do this(retrieving the tokens) using re module.
>
> In [33]: mat =
re.search(r'(\S+)-(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{4})',
'myfi-le-2015-02-09-19-08-45-4223')
>
> In [34]: mat
>
> Out[34]: <_sre.SRE_Match object; span=(0, 32),
match='myfi-le-2015-02-09-19-08-45-4223'>
>
> In [35]: mat.groups() Out[35]: ('myfi-le', '2015', '02', '09', '19',
'08', '45', '4223')
>
> In [36]: mat =
re.search(r'(\S+)-(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{4})',
'myfile-2015-02-09-19-08-45-4223')
> In [37]: mat
>
> Out[37]: <_sre.SRE_Match object; span=(0, 31),
match='myfile-2015-02-09-19-08-45-4223'> In [38]: mat.groups()
>
> Out[38]: ('myfile', '2015', '02', '09', '19', '08', '45', '4223')
>
> if you don't want fiddle with regex you can use parse module(
https://github.com/r1chardj0n3s/parse). but why use an external library
when stdlib already provides it? :)

I'm a stupid.
as soon as I saw strftime it looked like strptime and I assumed he is
trying to extract the tokens and wrote that stupid/unrelated mail.

PS: trying to read mailing list when you are half woke, is a bad idea and
trying reply to it is even bad idea.

Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heap Implementation

2016-02-09 Thread Cem Karan

On Feb 9, 2016, at 8:27 PM, srinivas devaki  wrote:

> 
> 
> On Feb 10, 2016 6:11 AM, "Cem Karan"  wrote:
> >
> > Eh, its not too bad once you figure out how to do it.  It's easier in C 
> > though; you can use pointer tricks that let you find the element in 
> > constant time, and then removal will involve figuring out how to fix up 
> > your heap after you've removed the element.
> >
> 
> If you can do it with C pointers then you can do it with python's 
> references/mutable objects. :)
> in case of immutable objects, use a light mutable wrapper or better use list 
> for performance.

I should have been clearer; it's easier to UNDERSTAND in C, but you can 
implement it in either language.  C will still be faster, but only because its 
compiled.  It will also take a lot longer to code and ensure that it's correct, 
but that is the tradeoff.

Thanks,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cygwin and Python3

2016-02-09 Thread Larry Hudson via Python-list

On 02/09/2016 08:41 AM, Fillmore wrote:


Hi, I am having a hard time making my Cygwin run Python 3.5 (or Python 2.7 for 
that matter).
The command will hang and nothing happens.



Just curious...

Since Python runs natively in Windows, why are you trying to run it with Cygwin?
I'm not implying that you shouldn't, just offhand I don't see a reason for it.

 -=- Larry -=-


--
https://mail.python.org/mailman/listinfo/python-list


Re: Cygwin and Python3

2016-02-09 Thread Mike S via Python-list

On 2/9/2016 7:26 PM, Larry Hudson wrote:

On 02/09/2016 08:41 AM, Fillmore wrote:


Hi, I am having a hard time making my Cygwin run Python 3.5 (or Python
2.7 for that matter).
The command will hang and nothing happens.



Just curious...

Since Python runs natively in Windows, why are you trying to run it with
Cygwin?
I'm not implying that you shouldn't, just offhand I don't see a reason
for it.

  -=- Larry -=-



Have you seen this?
http://www.davidbaumgold.com/tutorials/set-up-python-windows/

--
https://mail.python.org/mailman/listinfo/python-list


Re: There has to be a better way to split this string!

2016-02-09 Thread Cameron Simpson

On 10Feb2016 07:34, srinivas devaki  wrote:

On Feb 10, 2016 7:23 AM, "srinivas devaki" 
wrote:

On Feb 10, 2016 6:56 AM, "Anthony Papillion" 

wrote:

> I am using datetime.now() to create a unique version of a filename.
> When the final file is named, it will look something like:
> myfile-2015-02-09-19-08-45-4223

You can easily do this(retrieving the tokens) using re module.

[... complicated suggestion for the inverse problem ...]


I'm a stupid.
as soon as I saw strftime it looked like strptime and I assumed he is
trying to extract the tokens and wrote that stupid/unrelated mail.

PS: trying to read mailing list when you are half woke, is a bad idea and
trying reply to it is even bad idea.


Regrettably, when one is half awake one is unable to realise what a bad idea it 
may be:-)


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Importing two modules of same name

2016-02-09 Thread dieter
Carl Meyer  writes:
> ...
> If you omit the future-import in Python 2.7, `import config` will import
> the neighboring app/config.py by default, and there is no way to import
> the top-level config.py.

There is the "__import__" builtin function which allows to specify
the "parent package" indirectly via its "globals" parameter. This
way, you can import the "top-level" config (passing an empty "globals").

-- 
https://mail.python.org/mailman/listinfo/python-list