首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在一个简单的程序中重命名本地绝对文件路径并上传到github,这样就没有人知道我的目录了,这有关系吗?

在一个简单的程序中重命名本地绝对文件路径并上传到github,这样就没有人知道我的目录了,这有关系吗?
EN

Stack Overflow用户
提问于 2020-08-27 23:18:05
回答 1查看 19关注 0票数 0

我已经开始使用GitHub来显示一些非常简单的程序。https://github.com/MasonMcGerry

我想上传更多简单的程序,但它们中的许多都有我在程序中使用的目录和文件的完整和绝对文件路径。

我不想把它放在互联网上,因为那看起来不安全,但也许这并不重要。

我正在考虑创建一个新的项目克隆,然后将路径更改为虚构的内容,如/path/ to /this/file。这似乎会花费更长的时间,而且我会遇到调试问题,因为我会在本地主机上使用绝对文件路径进行编程,测试它们,然后为"GitHub ready/safe“版本重写文件路径。

我的本地主机上的工作版本和“克隆”都在我的计算机上,但只有“克隆”在它的目录中有.git文件。

下面的简单程序示例更改了文件路径。

代码语言:javascript
复制
# for converting tag types to another platforms design

# filepath
fp = '/Users/username/Desktop/Projects/Programs/tagConverter/'

IG = ['IG','ig','instagram','Instagram']
YT = ['YT','yt','youtube','Youtube','Youtube']
end = ['end','END','End','stop','STOP','Stop']
runState = True
# Instagram
def convIG():
    # takes convTxt.txt file, strips out commas and puts each item into array
    # line by line writes into convIG.txt
    # open up file /Users/username/Downloads/tagConverter/convTxt.txt
    # and read it
    f = open(fp + 'convTxt.txt','r')
    inconvIG = f.read()
    outconvIG = '#'+("#").join(inconvIG[0:].split(','))
    g = open(fp + 'convIG.txt','w')
    g.write(outconvIG.replace(' ',''))
    g.close()
    f.close()

# YouTube
"""
will need ML to separate recognizable words with spaces like NLP
other Instagram tags like '#Howto#DIY' will become CSV howto,diy
instead of the preferred 'How to, DIY'
probably will use 'in' operator to help recognize and separate words
i.e.
s = '#howto'
x = ''
if 'how' in s:
    x += 'how '
if 'to' in s:
    x += 'to '
print(x)
x == 'how to '
"""
def convYT():
    # takes convTxt.txt file, strips out # and puts each item into array
    # line by line writes into convYT.txt
    # open up file /Users/username/Downloads/tagConverter/convTxt.txt
    # and read it
    f = open(fp + 'convTxt.txt','r')
    inconvYT = f.read()
    outconvYT = (",").join(inconvYT[0:].split('#'))
    g = open(fp + 'convYT.txt','w')
    g.write(outconvYT)
    g.close()
    f.close()
    
def prompt():
    global runState
    prompt = input("Which Tag Type would you like to convert to?\n")
    if prompt in IG:
        convIG()
    elif prompt in YT:
        convYT()
    elif prompt in end:
        runState = False
    else:
        print('fail')
        
     
# indefinite loop, enter an end word listed in 'end' list
while runState == True:
    prompt()



"""
SOURCES:
https://stackoverflow.com/questions/2783969/compare-string-with-all-values-in-array
https://stackoverflow.com/questions/18132912/checking-if-a-value-is-equal-to-any-value-in-an-array
https://stackoverflow.com/questions/29101836/typeerror-function-object-is-not-subscriptable-python
Reuben Young colleague and friend
https://www.journaldev.com/23763/python-remove-spaces-from-string
https://www.programiz.com/python-programming/global-keyword
https://help.instagram.com/351460621611097

https://www.w3schools.com/python/gloss_python_global_variables.asp
https://beginnersbook.com/2019/03/python-any-function/
https://www.programiz.com/python-programming/list-comprehension

"""

我意识到这段代码非常简单,但随着我的进步,其中一些代码会变得更加复杂,这将是一个麻烦。

有没有解决办法,我是不是多疑了,或者误解了/误用了这项技术(git/github)?

EN

回答 1

Stack Overflow用户

发布于 2020-08-27 23:26:48

您不想公开您的本地文件系统,这是正确的。任何硬编码路径都应该是相对的,以避免让潜在的坏角色洞察你的机器是如何组织的。例外情况是系统默认目录,如C://Progam Files,其中所有windows计算机都存储特定类型的数据。

这里最好的解决方案是将这些文件放入某个resources目录下的项目中,并从那里直接访问它们。您还可以解析配置文件,该文件将指定在何处查找这些文件。例如,

代码语言:javascript
复制
tagConverterPath = "/Users/username/Desktop/Projects/Programs/tagConverter/"

当然,您需要将配置文件添加到.gitignore中,并且每个用户都需要定义自己的配置文件,除非您为他们提供了默认的配置文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63619140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档