Created
May 14, 2019 17:15
-
-
Save mbstacy/33cd3750b7ac09716a7bc61986d63004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def makeCamelCase(name,filename=False,removeSpecial=False): | |
""" | |
This funciton produces camelCase variable names or filenames. You can provide option to remove special characters. | |
ARGS: | |
name (string) | |
KWARGS: | |
filename (Boolean) - default False | |
removeSpecial (Boolean) - default false | |
""" | |
if filename: | |
name, file_extension = os.path.splitext(name) | |
ccase=''.join(x for x in name.title() if not x.isspace()) | |
ccase = ccase[0].lower() + ccase[1:] | |
if removeSpecial: | |
ccase = ''.join(e for e in ccase if e.isalnum()) | |
ccase = ccase[0].lower() + ccase[1:] | |
if filename: | |
return "{0}{1}".format(ccase,file_extension.lower()) | |
return ccase | |
names=["([Modification; of Polymer Network Properties/ through the)] Addition??? o.pdf","Modification of Polymer Network Properties through the Addition o.pdf"] | |
for itm in names: | |
print(makeCamelCase(itm,filename=True,removeSpecial=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment