Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

File Pool display images

Hi again!

I was trying to select images from the File Pool and display them on a canvas in a loop. I want a second canvas following the first one, with some text on it. This is a part of the code I have in the prepare phase (not the most sophisticated one!)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import random

list = [ ]

curve = ["shape2.jpg", "shape3.jpg","shape7.jpg","shape8.jpg", "shape9.jpg","shape11.jpg","shape12.jpg", "shape13.jpg", "shape14.jpg" ]

list.append(curve)

close = ["shape2.jpg", "shape3.jpg", "shape6.jpg", "shape7.jpg", "shape8.jpg", "shape9.jpg", "shape11.jpg", "shape12.jpg", "shape14.jpg"]

list.extend(close)

diag = ["shape1.02.jpg", "shape3.jpg", "shape5.jpg", "shape6.jpg", "shape13.jpg"]

list.extend(diag)

sym = ["shape2.jpg", "shape3.jpg", "shape4.jpg", "shape5.jpg", "shape6.jpg", "shape7.jpg", "shape10.jpg", "shape14.jpg"]

list.extend(sym)
text = ['curve?', 'sym?', 'diag?', 'sym']

for sym in list:
list_sym = random.choice(list)
chosen_text = random.choice(text)
sym_cnvs = self.offline_canvas()
xc = sym_cnvs.xcenter()
yc = sym_cnvs.ycenter()
text_cnvs = self.offline_canvas()
cx = sym_cnvs.xcenter()
cy = sym_cnvs.ycenter()
symbol = exp.get_file(list_sym)
sym_cnvs.image(symbol, xc, yc)
text_cnvs.text(chosen_text, cx, cy)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

When I try to run this part, I get an error as follows:
IOError: The picture file '['shape2.jpg', 'shape3.jpg', 'shape7.jpg', 'shape8.jpg', 'shape9.jpg', 'shape11.jpg', 'shape12.jpg', 'shape13.jpg', 'shape14.jpg']' does not exist.

Instead, when I try to run only the following code, in an attempt to debug:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import random

list = []

curve = ["shape2.jpg", "shape3.jpg","shape7.jpg","shape8.jpg", "shape9.jpg","shape11.jpg","shape12.jpg", "shape13.jpg", "shape14.jpg" ]

list.append(curve)

close = ["shape2.jpg", "shape3.jpg", "shape6.jpg", "shape7.jpg", "shape8.jpg", "shape9.jpg", "shape11.jpg", "shape12.jpg", "shape14.jpg"]

list.extend(close)

diag = ["shape1.02.jpg", "shape3.jpg", "shape5.jpg", "shape6.jpg", "shape13.jpg"]

list.extend(diag)

sym = ["shape2.jpg", "shape3.jpg", "shape4.jpg", "shape5.jpg", "shape6.jpg", "shape7.jpg", "shape10.jpg", "shape14.jpg"]

list.extend(sym)
print list

text = ['curve?', 'sym?', 'diag?', 'sym']

list_sym = random.choice(list)
print list_sym

chosen_text = random.choice(text)
print chosen_text

sym_cnvs = self.offline_canvas()
symbol = exp.get_file(list_sym)
sym_cnvs.image(symbol)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

It prints out the values in list, list_sym and chosen_test as expected but I still get an error as follows: AttributeError: 'experiment' object has no attribute 'sym_cnvs'

Can someone please pin point where I'm going wrong? Could it be something in my code or the fact that it isn't able to get the path for images in the file pool?

Many thanks in advance!

Regards,
Anupama

Comments

  • HI Anupama,

    Be aware of the difference between appending to a list and extending a list (see here)

    So, when you do this:

    list = [ ] # as a sidenote, it is not wise, to call a list "list" as this might cause unexpected behaviour when you want to create a list with the list command
    curve = ["shape2.jpg", "..." ,"shape13.jpg"]
    list.append(curve)
    close = ["shape2.jpg", "...", "shape6.jpg"]
    list.extend(close)
    

    your list would contain following: `[["shape2.jpg", "..." ,"shape13.jpg"],"shape2.jpg", "...", "shape6.jpg"]. So first, another list, and then three more items. See what I mean?

    Therefore, you first error occurs, because you want to pass a list to exp.get_file(), which expects a string. I suppose the reason your debug attempt threw another error, is simply chance because you are randomly picking an item from the list, which in this case happened to be a proper string.

    Does this make sense?

    Eduard

    Buy Me A Coffee

  • Hi Eduard,

    Thanks for the feedback! I do notice what you mean by the difference between 'append' and 'extend'. I converted all the 'appends' to 'extends' and now I have one unified list with all the images.

    When I randomly pick out images from the list, it is now always a string. However, when I try to create a canvas (inside the loop) to display this image, it still throws an error like "AttributeError: 'experiment' object has no attribute 'sym_cnvs' What could be the reason for this?

    Thanks again,
    Anupama

  • Which OpenSesame version do you use? Could you post the entire code you're using right now(e.g. uploading it on pastebin.com) or even the entire experiment?

    Thanks,

    Eduard

    Buy Me A Coffee

  • Hi Eduard,

    Thank you for your prompt reply! I'm using OS 2.9.7.
    The link to my experiment is http://pastebin.com/sjqKuZNK

  • Hi Eduard,

    Do you know why it won't work yet?

    Thanks,
    Anupama

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games