Import if condition is correct

2006-10-28 Thread MindClass
Is possible import a library according to a condition?

if Foo = True:
import bar

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


Re: Import if condition is correct

2006-10-28 Thread MindClass

Georg Brandl wrote:
> MindClass wrote:
> > Is possible import a library according to a condition?
> >
> > if Foo == True:
> > import bar
> >
>
> Why don't you try it?
>
I thinked that could be another way for import statement.

In that case I'll have to set a global variable before of the import
statements although I'd prefer not use them.

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


Re: Import if condition is correct

2006-10-28 Thread MindClass

Steve Holden wrote:
> I'm guessing that you think this might be necessary to avoid importing
> the same module multiple times: it's not. Python only runs the module's
> code the first time the module is imported into a program. A further
> import statement effectively does noting, because the interpreter sees
> (from an entry in the sys.modules dictionary) that the module is already
> present.
>
The problem is that I've to import different libraries according to the
ORM (SQLObject, SQLAlchemy, etc)

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


Reading standard input

2006-10-28 Thread MindClass
The program shows a license text, then the user has to accept the
license (or not).
Is there another way to get text from console? (that using
sys.stdin.read)

foo = sys.stdin.read(3)
if foo != 'yes'
sys.exit(0)

I also would to trap the KeyboardInterrupt for that doesn't show that
message. How would it be possible?

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


Data not flushed at the moment

2006-11-22 Thread MindClass
I've to modifying a file, then I use a method imported that access to
that file and has to read the new data, but they are not read ( as if
the data were not flushed at the moment even using .close()
explicitly).

---
...
...
# If it is not installed, it looking for the line and insert it.
if not is_application:
print "Activating I18n application ..."
writefile_line = 0
a = fileinput.input(settings, inplace=1)
#for line in fileinput.input(settings, inplace=1):
for line in a:
writefile_line += 1
if writefile_line == readfile_line:
print "'%s'," % application_name
print line[:-1]
else:
print line[:-1]
a.close()

update()

def update():
# Update the data base.
try:
from django.core.management import syncdb
except ImportError, err:
print "Can't import from Django: %s" % err
sys.exit(1)

syncdb()
---

Note that it only fails if the update() method is run inner of 'if not
is_application', and I don't understand because it is happening so. But
the problem is that I need run it when that condition is performed. Any
idea?

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


Re: Data not flushed at the moment

2006-11-22 Thread MindClass
Here it's very well explained:
http://groups.google.com/group/django-developers/browse_thread/thread/7bcb01ec38e7e6cd

syncdb() method:
http://code.djangoproject.com/browser/django/trunk/django/core/management.py#L435

But I'm not sure if is a django problem or from python.


MindClass ha escrito:

> I've to modifying a file, then I use a method imported that access to
> that file and has to read the new data, but they are not read ( as if
> the data were not flushed at the moment even using .close()
> explicitly).
>
> ---
> ...
> ...
> # If it is not installed, it looking for the line and insert it.
> if not is_application:
> print "Activating I18n application ..."
> writefile_line = 0
> a = fileinput.input(settings, inplace=1)
> #for line in fileinput.input(settings, inplace=1):
> for line in a:
> writefile_line += 1
> if writefile_line == readfile_line:
> print "'%s'," % application_name
> print line[:-1]
> else:
> print line[:-1]
> a.close()
>
> update()
>
> def update():
> # Update the data base.
> try:
> from django.core.management import syncdb
> except ImportError, err:
> print "Can't import from Django: %s" % err
> sys.exit(1)
>
> syncdb()
> ---
>
> Note that it only fails if the update() method is run inner of 'if not
> is_application', and I don't understand because it is happening so. But
> the problem is that I need run it when that condition is performed. Any
> idea?

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