Hey guys, I know this will have an easy answer, but I have been awake far too long to see it :P

I am doing some coding with classes in python, and it just isn't working.
Here is the code:

from bpy import *
from os import *
from mathutils import *
from random import *
base_dir = "C:/Users/Alienware/Desktop/aftereffects/project/content/"
area = "palmerston"
dir_ads = base_dir+"ads/"+area
length = 50
class section(object):
    def __init__(self,dir,base):
        self.content=listdir(self.dir)
        shuffle(self.content)
        self.max=len(self.content)
        self.count=1
        
ad_5_1500 = section(dir="/5/1500",base=dir_ads)

Basically I am setting up a class so I can call ad_5_1500.content to get the contents etc.
it just needs the same effect as what was there originally

dir_ads_5_1500=dir_ads+"/5/1500"
content_ads_5_1500 = listdir(dir_ads_5_1500)
shuffle(content_ads_5_1500)
max_ads_5_1500 = len(content_ads_5_1500)
count_ads_5_1500 = 1

as you can see I am not a python developer so any help would be appreciated :D

Recommended Answers

All 2 Replies

line 11 you use self.dir when you have parameter dir (which you did not save as instance variable). listdir is os.listdir? I would prefer to import os not from os import *. Base is also not used.

Thank you for your help, I had a good nights sleep and it all makes so much more sense now,
I'm a php developer not a python developer lol
Here is the fixed script:

from bpy import *
from os import *
from mathutils import *
from random import *
base_dir = "C:/Users/Alienware/Desktop/aftereffects/project/content/"
area = "palmerston"
dir_ads = base_dir+"ads/"+area
length = 50

class section:
    def __init__(self,directory,base):
        self.count=1
        self.directory=directory
        self.base=base
        self.content=listdir(self.base+self.directory)
        shuffle(self.content)
        self.max=len(self.content)
ad_5_1500 = section("/5/1500",dir_ads)

This is coding for blenders python api, so things like os.listdir and random.shuffle are shortened.

Thank you for your help :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.