python autocomplete-generator.py
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python autocomplete-generator.py相关的知识,希望对你有一定的参考价值。
# coding: utf-8
# author: Cody Kochmann
# date: Sat 06 Feb 2016 09:30:29 AM EST
# description: interactively make sublime text completitions
""" sample json for .sublime-completions file
{
"scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",
"completions":
[
{ "trigger": "a", "contents": "<a href=\"$1\">$0</a>" },
{ "trigger": "abbr", "contents": "<abbr>$0</abbr>" },
{ "trigger": "acronym", "contents": "<acronym>$0</acronym>" },
"ninja",
"robot",
"pizza"
]
}
"""
global autocomplete_dictionary
autocomplete_dictionary=[]
class Autocomplete_Dictionary:
def __init__(self, save_path=''):
self.completition
import json
class Completion:
def __init__(self, scope='', contents='', trigger=''):
self.data={}
self.data['scope']=scope
self.data['completions'] = []
if trigger != '':
completion_data={}
completion_data['trigger']=trigger
completion_data['contents']=contents
self.data['completions'].append(completion_data)
else:
self.data['completions'].append(contents)
self.to_string=(json.dumps(self.data))
def remove_all(substring='',target=''):
if substring in target:
target = ''.join(target.split(substring))
return target
def append_to_file(s='',path=''):
with open(path,'a') as f:
f.write(s+'\n')
def write_to_file(s='',path=''):
with open(path,'w') as f:
f.write(s)
def read_file(path=''):
with open(path,'r') as f:
return f.read()
def random_hash(length=256):
import random
return random.getrandbits(length)
file_name='sublime-completions/'+str(random_hash())+'.sublime-completions'
contents=raw_input('enter the completition ( one line ): ')
trigger=raw_input('enter the trigger ( leave blank if none ): ')
scope=raw_input('enter the scope ( example: py ): ')
snippet = Completion(scope,contents,trigger)
write_to_file(snippet.to_string, file_name)
以上是关于python autocomplete-generator.py的主要内容,如果未能解决你的问题,请参考以下文章
Python代写,Python作业代写,代写Python,代做Python
Python开发
Python,python,python
Python 介绍
Python学习之认识python
python初识