Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Allie
Jan 17, 2004

wins32767 posted:

Just out of curiosity, what do you have against Pylons?

I'll quote what I wrote on another site a while back:

quote:

I see what you're saying here about how Pylons makes heavy use of WSGI chaining, but I really just cannot fathom that Django is "approaching" Pylons. Perhaps things have improved since I last used Pylons, but there were so many issues with it that drove me absolutely crazy and eventually drove me away from the framework all together.

Off the top of my head:

- Poorly written, half written, scattered, or plain old missing documentation all over the place.

- Poor release coordination and communication.

- Version incompatibility hell between different releases of its components/dependencies.

- Incomplete solutions for basic things like form generation. At the time that I was using Pylons they seemed to jump between a quite a few different libraries, none of which really worked well.

- Tons of magic that both offended my sensibilities and made debugging a nightmare.

To be honest, I don't think any Python web framework was quite "there" at that time, but I think today Django has far exceeded Pylons.

Also, I'm not sure I'd consider Pylons a micro-framework.

This was in the context of a discussion about djng.

And if you couldn't tell, I prefer Django. I was skeptical of it when I first came upon it in the pre-1.0 days, and that's what eventually led me to Pylons. However, since then, Django has improved by a vast amount, and it's now really easy to pump out web apps with it.

That said, I do prefer the mix-n-match WSGI approach for low level/high performance web services.

Adbot
ADBOT LOVES YOU

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo
Django question time:

I'm doing some sort of galactic model, and I have the following classes in a models.py:

code:
class Star(models.Model):
    name = models.CharField(max_length=200)
    xcoord = models.FloatField()
    ycoord = models.FloatField()
    zcoord = models.FloatField()
    def __unicode__(self):
        return self.name + ' (' + str(self.xcoord) + ', ' + str(self.ycoord) + ', ' + str(self.zcoord) + ')'

class Satellite(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField(blank=True, null=True)
    system = models.ForeignKey(System, related_name='satellites')
    def __unicode__(self):
        return self.name

class Asteroid(Satellite):
    pass
    
class Planet(Satellite):
    orbital = models.IntegerField()

class Moon(Satellite):
    suborbital = models.IntegerField()
    orbits = models.ForeignKey(Planet, related_name='moons')
What should I do so I can refer to an s.planets object containing all objects of class Planet with system==s?

edit: would planets = self.satellites.filter(orbital>0) work in Star?

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo

Baruch Obamawitz posted:

Django question time:

It looks like I should put something like the following in Star:

code:
    def _get_planets(self):
        return self.planets
    def _set_planets(self):
        SOMETHING THAT SELECTS ONLY THE PLANETS IDK
    planets = property(_get_planets, _set_planets)
Just have to figure out _set_planets(self) now, I guess.

WhiskeyJuvenile fucked around with this message at 03:16 on Oct 10, 2009

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo

Baruch Obamawitz posted:

Just have to figure out _set_planets(self) now, I guess.

code:
for satellite in self.satellites.all():
  if type(satellite).__name__ == 'Planet'):
    self.planets.append(satellite)
  continue
Yes?

edit: apparently not!

WhiskeyJuvenile fucked around with this message at 03:26 on Oct 10, 2009

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo
in Star
code:
    def _get_planets(self):
        return self.planets
    def _set_planets(self,planet):
        self.planets.append(planet)
    planets = property(_get_planets, _set_planets)
in Planet
code:
    def __init__(self, *args, **kwargs): 
        super(Planet, self).__init__(*args, **kwargs) 
        self.star._set_planets(self)
How about this?

edit: Or this?

in Planet:
code:
    orbits = models.ForeignKey(Star, related_name='planets')
    def __init__(self, *args, **kwargs): 
        super(Planet, self).__init__(*args, **kwargs) 
        self.orbits = self.star
   def save(self):
        self.orbits = self.star
        super(Planet, self).save()

WhiskeyJuvenile fucked around with this message at 04:26 on Oct 10, 2009

king_kilr
May 25, 2007

Baruch Obamawitz posted:

in Star
code:
    def _get_planets(self):
        return self.planets
    def _set_planets(self,planet):
        self.planets.append(planet)
    planets = property(_get_planets, _set_planets)
in Planet
code:
    def __init__(self, *args, **kwargs): 
        super(Planet, self).__init__(*args, **kwargs) 
        self.star._set_planets(self)
How about this?

Uhh, this is terrible. Why would assignment append to something....

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo

king_kilr posted:

Uhh, this is terrible. Why would assignment append to something....

yes, it is terrible (and it actually validates but doesn't create any sort of data structure so I guess it doesn't work!)

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo
code:
class Planet(Satellite):
    orbital = models.IntegerField()
    orbits = models.ForeignKey(Star, related_name='planets')
    def save(self):
        self.orbits = self.star
        super(Planet, self).save()
This works! Too bad it's so inelegant!

edit: babby's first time using python

nbv4
Aug 21, 2002

by Duchess Gummybuns
My webhost (webfaction) has python 2.6 installed, but the apache instance they provide uses python 2.5. They provide instructions on how to compile your own version of apache that uses 2.6, but it's a pain in the rear end. Is it possible to use virtualenv instead to use 2.6 with apache?

king_kilr
May 25, 2007

nbv4 posted:

My webhost (webfaction) has python 2.6 installed, but the apache instance they provide uses python 2.5. They provide instructions on how to compile your own version of apache that uses 2.6, but it's a pain in the rear end. Is it possible to use virtualenv instead to use 2.6 with apache?

This doesn't make sense, a virtualenv controls the enviroment it's python executable runs in, it can't make apache use a different python version.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

Baruch Obamawitz posted:

failures

You had the right idea with your original models and it all falls apart because you need to make Satellite an abstract model, look it up.

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo

jupo posted:

You had the right idea with your original models and it all falls apart because you need to make Satellite an abstract model, look it up.

I don't think that will fix the Star.planets issue though, will it?

I was thinking of a type = CharField(max_length=10) where the subclass save() functions do type = type(self).__name__

wins32767
Mar 16, 2007

Milde posted:

<snip>
That said, I do prefer the mix-n-match WSGI approach for low level/high performance web services.

All those itemized complains are very cogent, though the last two are the only ones that haven't been improved upon, at least to my satisfaction. Certainly, when I was trying to decide on a framework ~2 years ago they were all more or less problems. Django just isn't flexible enough for the things I'm doing with my web framework, especially in the area of the model. The first system I wrote in Pylons is up to ~7.5 million records in the main table; if I hadn't been able to apply some database foo with triggers and stored procedures performance would be in the crapper. At the time, I didn't get the impression that the Django model could handle that sort of thing well; hell, Pylons has some limitations in that respect.

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo
Doesn't python do some sort of weird nested for loop thing?

edit: something like

code:
for x in y in z
or something?

ATLbeer
Sep 26, 2004
Über nerd

Baruch Obamawitz posted:

Doesn't python do some sort of weird nested for loop thing?

edit: something like

code:
for x in y in z
or something?

List Comprehension?
http://docs.python.org/tutorial/datastructures.html#list-comprehensions

Allie
Jan 17, 2004

No, Python doesn't do anything like that. You can choose one of the following:

1. Nested for loops.

code:
>>> for a in x:
...     for b in y:
...         
2. A list comprehension with multiple for clauses.

code:
>>> [... for a in x for b in y]
3. Fancy poo poo for jerks.

code:
>>> import itertools
>>> for a, b in itertools.product(x, y):
...        
You probably just want #1.

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo
Yay, I solved the earlier problem:

code:
    def _get_planets(self):
        return Planet.objects.filter(satellite_ptr__in=self.satellites.all()).order_by('orbital')
    
    def _get_asteroids(self):
        return Planet.objects.filter(satellite_ptr__in=self.satellites.all()).order_by('name')

    def _get_moons(self):
        return Moon.objects.filter(satellite_ptr__in=self.satellites.all()).order_by('planet__orbital','suborbital')
        
    planets = property(_get_planets)
    asteroids = property(_get_asteroids)
    moons = property(_get_moons)

ATLbeer
Sep 26, 2004
Über nerd

Milde posted:


1. Nested for loops.

code:
>>> for a in x:
...     for b in y:
...         
You probably just want #1.

If anyone else is ever going to read your code #1. List comprehension is really nice but, nested for is so much easier to debug and read.

VirtuaSpy
Jul 26, 2002

OMG WTF FIREEEE!!
I am using python 2.6 on the Mac and running in to a bit of trouble in getting a fresh install of python26 + pylab to work. I use Macports to manage the python install and packages, and for some reason I cannot import pylab in my standard python shell. But the weird thing is that it works fine when using the spyder python IDE that I recently came across, in which the python shell looks identical.

Here's what I get when I import pylab in the spyder interactive shell:

code:
>>> import pylab
>>> pylab
<module 'pylab' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pylab.pyc'>
And when I import with a python shell, started from python on the command line:

code:
>>> import pylab
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/matplotlib/pylab.py", line 247, in <module>
    from matplotlib.pyplot import *
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/matplotlib/pyplot.py", line 78, in <module>
    new_figure_manager, draw_if_interactive, show = pylab_setup()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
    globals(),locals(),[backend_name])
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/matplotlib/backends/backend_wxagg.py", line 23, in <module>
    import backend_wx    # already uses wxversion.ensureMinimal('2.8')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/matplotlib/backends/backend_wx.py", line 127, in <module>
    wxversion.ensureMinimal('2.8')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/wxversion.py", line 209, in ensureMinimal
    import wx, webbrowser
ImportError: No module named wx
I thought it might have something to do with the PATH variable, but they look the same.

PATH from spyder:

code:
>>> sys.path
['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pydee-0.4.23-py2.6.egg',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/spyder-1.0.0rc3-py2.6.egg',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages',
'/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin', '/usr/X11/bin', '/usr/texbin', '/opt/local/bin',
'/opt/local/sbin', '/usr/local/bin/Dakota/bin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Numeric',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/IPython/Extensions']
>>> 
PATH from python shell:

code:
>>> sys.path
['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pydee-0.4.23-py2.6.egg',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/spyder-1.0.0rc3-py2.6.egg',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages',
'/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin', '/usr/X11/bin', '/usr/texbin', '/opt/local/bin',
'/opt/local/sbin', '/usr/local/bin/Dakota/bin',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Numeric',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyObjC']
Both Python shells are using Python 2.6.3 from my /opt/local/bin/python. It also fails if I try to use ipython.

This is driving me crazy! What else should I be looking at here?

Modern Pragmatist
Aug 20, 2008

VirtuaSpy posted:

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/...
python2.6/site-packages/wxversion.py", line 209, in ensureMinimal
import wx, webbrowser
ImportError: No module named wx

Python not finding wxpython is your problem. Check to make sure that you have installed wxpython properly with macports.

Edit: Also worth noting that you need version 2.8+

code:
sudo port install py26-wxpython

Modern Pragmatist fucked around with this message at 23:50 on Oct 12, 2009

VirtuaSpy
Jul 26, 2002

OMG WTF FIREEEE!!

Modern Pragmatist posted:

Python not finding wxpython is your problem. Check to make sure that you have installed wxpython properly with macports.

Edit: Also worth noting that you need version 2.8+

code:
sudo port install py26-wxpython

I see. So py26-wxpython doesn't currently build on Snow Leopard (per http://trac.macports.org/ticket/20952), and I guess that is where my error is originating, since it can't find wxpython. I'll just keep tracking that bug.

I am just stumped as to why it is working okay in spyder.

Thanks for the help!

sink
Sep 10, 2005

gerby gerb gerb in my mouf

ATLbeer posted:

If anyone else is ever going to read your code #1. List comprehension is really nice but, nested for is so much easier to debug and read.

List comprehensions are faster.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

sink posted:

List comprehensions are faster.

Worrying about speed in Python is a great way to waste your time.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Avenging Dentist posted:

Worrying about speed in Python is a great way to waste your time.

I recently switched to using Python for my project Euler problems and I've run into some speed issues. Although they can usually be fixed by using python's bad rear end iterators instead of list comprehension.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I just do the performance-sensitive stuff in C.

sink
Sep 10, 2005

gerby gerb gerb in my mouf

Avenging Dentist posted:

Worrying about speed in Python is a great way to waste your time.

I think they look nicer than for loops, too.

Allie
Jan 17, 2004

sink posted:

I think they look nicer than for loops, too.

They don't necessarily serve the same purpose. Using list comprehensions implies that you're transforming your input in some manner. For loops don't have to build up anything or do anything to any list - they can have side effects, and you have more control flow options.

That said, I absolutely love list comprehensions. They're so concise and they're easy to read.

I must admit, though, I sometimes secretly lust for a universe where Python has Ruby-style iteration with anonymous functions.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
If only Guido didn't hate functional programming :sigh:

WhiskeyJuvenile
Feb 15, 2002

by Nyc_Tattoo
oh what the christ is this

bad python or bad django?

code:
>>> foo = Class.objects.filter(id=3) # there is no Class object stored with this id
>>> foo
[]
>>> foo == []
False

No Safe Word
Feb 26, 2005

Baruch Obamawitz posted:

oh what the christ is this

bad python or bad django?

code:
>>> foo = Class.objects.filter(id=3) # there is no Class object stored with this id
>>> foo
[]
>>> foo == []
False

foo is a queryset, it just pretty-prints like a list

just check foo.count() I think

Threep
Apr 1, 2006

It's kind of a long story.
if foo/if not foo work.

I think it's because len(foo) returns 0 when it's empty and empty sequences evaluate to false. Someone correct me otherwise.

Ninja edit: Actually it probably isn't since you're not supposed to call len(foo) because it fetches the whole QuerySet but the logic was still sound

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Design question: which is more "Pythonic" (or "which do you prefer")?

And before someone says "don't use camel-case", I'm (mostly) replicating an interface from another language, so it's staying that way.

Here's the common stuff: specify some input coordinates in the source basis (XYZ by default) and return the coordinates converted into the destination basis (XYZ by default). This version infers the dimension of the basis from the dimension of the entities (i.e. edges => U, faces => UV).
code:
geom.getEntCoords(input_coords, src=src_entities)
geom.getEntCoords(input_coords, dest=dest_entities)
geom.getEntCoords(input_coords, src=src_entities, dest=dest_entities)
As an optimization (and to assert that you're getting back coordinates in the dimension you expected), you can also explicitly specify the basis, but here's where the question is: which syntax?

(A)
code:
geom.getEntCoords(input_coords, src=(Geom.u, src_entities))
geom.getEntCoords(input_coords, dest=(Geom.uv, dest_entities))
geom.getEntCoords(input_coords, src=(Geom.u, src_entities), dest=(Geom.uv, dest_entities))
(B)
code:
geom.getEntCoords(input_coords, src=src_entities, src_basis=Geom.u)
geom.getEntCoords(input_coords, dest=dest_entities, dest_basis=Geom.uv)
geom.getEntCoords(input_coords, src=src_entities, src_basis=Geom.u, dest=dest_entities, dest_basis=Geom.uv)
I like (A) for brevity, but it might be a little bit obfuscated.

tripwire
Nov 19, 2004

        ghost flow
I would say go for A, if only because to me it seems MORE readable. You know that all the variables in the tuple are required so you won't have to find out the hard way when the function throws back a TypeError or silently uses a default keyword argument that you might not intend. To me it seems more explicit in A, and explicit is usually better than implicit in python, if that makes any sense.

nbv4
Aug 21, 2002

by Duchess Gummybuns
Why not just support both? PIL, matplotlib, and a few others that I know of have similar issues where they let you enter arguments either individually, or in tupled groups.

bitprophet
Jul 22, 2004
Taco Defender

Milde posted:

I must admit, though, I sometimes secretly lust for a universe where Python has Ruby-style iteration with anonymous functions.

The past few weeks I've been really starting to warm up to some of Ruby's ways of doing things, both the extra syntactical sugar and the blocks/emphasis on message-passing. And RubyGems kicks easy_install's rear end (though their answer to virtualenv is still pre-alpha.)

This is part Stockholm Syndrome (I work in a Rails shop) and part legitimate "you know that does look a bit nicer / is a bit easier to write than the equivalent Python".

If only the community wasn't so loud, noisy and busy tripping over itself in its haste to out-douchebag everyone else. For every legitimately cool person (like most of the Github team) there's at least a hundred people who describe every. single. project of theirs as "The most awesomeness of awesome hotness since sliced sexy! brought to you by a Rockstar Programmer :smug:"

And then there's the fact that testing is huge -- which is great -- but non-API documentation (or non barebones API documentation, even) is like the bottom of everybody's loving list :suicide:

So compared to all that, Python -- even with the Philip J Ebys and the Massimo DiPierros -- is a huge whiff of fresh air. Good job, guys :hfive:

bitprophet fucked around with this message at 05:15 on Oct 15, 2009

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

nbv4 posted:

Why not just support both? PIL, matplotlib, and a few others that I know of have similar issues where they let you enter arguments either individually, or in tupled groups.

I wouldn't exactly use a library whose primary purpose is "maintaining Matlab's interface" as the basis for design. Besides, that would go against Python's "there's only one way to do it" philosophy.

EDIT: to be fair, this is mostly an excuse because I don't like (B).

Avenging Dentist fucked around with this message at 19:40 on Oct 15, 2009

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

bitprophet posted:

"The most awesomeness of awesome hotness since sliced sexy! brought to you by a Rockstar Programmer :smug:"

It's a good general rule that "rockstar programmers" don't write web stuff, which is what makes the Rails community all the more sad.

Mikey-San
Nov 3, 2005

I'm Edith Head!

Avenging Dentist posted:

It's a good general rule that "rockstar programmers" don't write web stuff, which is what makes the Rails community all the more sad.

god:drat:

madey
Sep 17, 2007

I saved the Olympics singlehandedly
I need some help for a project Euler question.
It's question 8:Find the greatest product of five consecutive digits in the 1000 digit number.
it is only my first day learning a programming language so sorry if my code is retarded or inefficient. But this is what I have wrote.

code:
string= 'large number'
a=-1
b=0
c=1
d=2
e=3
f=0
g=0
h=0
i=0
j=0
k=0
listofmultiplied=[]
while e<100:
    a=a+1
    b=b+1
    c=c+1
    d=d+1
    e=e+1
    f=string[a]
    g=string[b]
    h=string[c]
    i=string[d]
    j=string[e]
    k=f*g*h*i*j
    listofmultiplied.append(k)
listofmultiplied.sort()
print(listofmultiplied)
But I get an error at 'k=f*g*h*i*j' which says:
TypeError: can't multiply sequence by non-int of type 'str'.
where am I going wrong?

Adbot
ADBOT LOVES YOU

yippee cahier
Mar 28, 2005

made of paper posted:

But I get an error at 'k=f*g*h*i*j' which says:
TypeError: can't multiply sequence by non-int of type 'str'.
where am I going wrong?

Just as the message says, you're trying to multiply single character strings together. Use the int() function to interpret the value of the string.

There are other things you should try before moving on to another problem. First, try to get rid of some variables -- you could use a single variable as the index in the array and then add an offset when accessing the array: string[a], string[a+1], string[a+2], etc. 'f' and on aren't used except to temporarily hold values before multiplying. Why not start by checking out the *= operator?

I realize you're just learning the language, but there's a couple really awesome python features that you should know about. Really, you ought to check out the section of your tutorial on the for loop, slicing and list comprehensions.

  • Locked thread