Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
The "String Method" as shown in, for example:
teststring = "[Syllabus]Sociology.131.AC.Race.and.Ethnicity.in.the.United.States (Spring 2012).docx" print teststring.replace('.', ' ')
"[Syllabus]Sociology 131 AC Race and Ethnicity in the United States (Spring 2012) docx"
is fantastic and the script I'm writing involves A LOT of text manipulation, it's a lot of what I'm doing and as I add features it continues to be important.
One of the common manipulations I'm doing is:
teststring = "[Syllabus]Sociology.131.AC.Race.and.Ethnicity.in.the.United.States (Spring 2012).docx" def f_type(f): return f.split('/')[-1] if os.path.isdir(f) else re.split(r'(\[Syllabus\]|\[Syllabus \d+\]|\[Video\]|)(.*?)( \(Fall \d+\)| \(Spring \d+\)| \(Summer \d+\)|)(\.part\d+\.rar$|\.\w+$)', f.split('/')[-1])[1] def f_name(f): return f.split('/')[-1] if os.path.isdir(f) else re.split(r'(\[Syllabus\]|\[Syllabus \d+\]|\[Video\]|)(.*?)( \(Fall \d+\)| \(Spring \d+\)| \(Summer \d+\)|)(\.part\d+\.rar$|\.\w+$)', f.split('/')[-1])[2] def f_term(f): return f.split('/')[-1] if os.path.isdir(f) else re.split(r'(\[Syllabus\]|\[Syllabus \d+\]|\[Video\]|)(.*?)( \(Fall \d+\)| \(Spring \d+\)| \(Summer \d+\)|)(\.part\d+\.rar$|\.\w+$)', f.split('/')[-1])[3] def f_ext(f): return f.split('/')[-1] if os.path.isdir(f) else re.split(r'(\[Syllabus\]|\[Syllabus \d+\]|\[Video\]|)(.*?)( \(Fall \d+\)| \(Spring \d+\)| \(Summer \d+\)|)(\.part\d+\.rar$|\.\w+$)', f.split('/')[-1])[4] print f_type(teststring) print f_name(teststring) print f_term(teststring) print f_ext(teststring)
[Syllabus] Sociology.131.AC.Race.and.Ethnicity.in.the.United.States (Spring 2012) .docx
But I'd like to be able to add: ".ftype()", ".fname()", ".fterm()", and ".fext()" methods (corresponding to these functions I have). And I have no idea how to do that.
I'd be looking to use it in a bunch of different functions in the script (so it wouldn't be class-bound or anything).
I can't even figure out what I should be google-ing. But how can I add these methods?
P.S. The names of the methods aren't really important--so if I have to change these names to keep from conflicting with built-in methods or something that's okay.
EDIT: I'm looking to be able to use this method for things like:
def testfunction(f1, f2): print 'y' if f1 REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
You can't add methods to built-in types like str.
str
You can, however, create a subclass of str and add the methods you want. As a bonus, add @s://forum.tuteehub.com/tag/property">property so you don't need to call the method to get the value.
@s://forum.tuteehub.com/tag/property">property
class MyString(str): @s://forum.tuteehub.com/tag/property">property def f_type(f): return f.split('/')[-1] if os.path.isdir(f) else re.split(r'(\[Syllabus\]|\[Syllabus \d+\]|\[Video\]|)(.*?)( \(Fall \d+\)| \(Spring \d+\)| \(Summer \d+\)|)(\.part\d+\.rar$|\.\w+$)', f.split('/')[-1])[1] s = MyString(teststring) s.f_type
Normally you'd use self as the name for the first parameter in a method's argument list (the one that receives the reference to the instance the method is attached to). In this case I just used f because your expression was already written to use it.
self
f
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.