Anyone know how to use the remove-emoji library in Python?
Documentation details or any solid code would be appreciated.
Follow the link that you provided to the library.
Extract the contents of the archive.
You'll notice that there is only one function in the entire library;
def remove_emoji(text):
text = text.decode('utf8')
return emoji_pattern.sub(r'', text).encode('utf8')
The only thing you need to do to use this library is call remove_emoji with the text you wish to have the emoji removed from.
For libraries like this with no documentation but only one simple task, the best thing you can do is look at the source code. Even in larger libraries, the source code is the only point of truth.
Related
I am looking for a program or simply documentation (if it's part of windows) of a library where you can edit an image directly, push it to the screen, and nothing else. Basically what could be a framework for a graphics library, but not giving any aid in terms of drawing things.
Pillow is a fork of the Python Imaging Library (PIL). Find its official docs here, and the very handy chapter on it in Automate the Boring Stuff With Python.
If you have specific needs as to what you mean by editing, please elaborate if I've missed the mark.
I would suggest looking into the PPM image filetype. This filetype, when provided a header, allows you to simply output "0 0 0" or any other values for one pixel. You print how many of these you want in your rows and columns, and it'll construct an image for you. This filetype is especially helpful in quickly implementing graphical representations of solutions
Refer to http://netpbm.sourceforge.net/doc/ppm.html for a quick guide!
I'd like to implement an image recoloring algorithm to produce results similar to what is shown here:
http://www.morethantechnical.com/2010/06/24/image-recoloring-using-gaussian-mixture-model-and-expectation-maximization-opencv-wcode/
but using Python. However, I'm not sure where to start. I've been playing around with OpenCV but the functions mentioned in the article (expectation maximization and GMM) don't seem to be available in Python API. Can somewhat point me in the right direction as to what tools/libraries I should be using?
First option is just implement this code in Python. It looks like all functions mentioned in article are avaible in Python API. CvEM is just EM (in module cv2):
>>> cv2.EM.__doc__
'EM([, nclusters[, covMatType[, termCrit]]]) -> <EM object>'
there is no CvEMParams, because EM already handles it. If you are looking for any other function/object, type dir(cv2) in Python console and most likely you will find what you are looking for. Quite often things in Python API has slightly different names, but still it's not a big problem to find them. Note that some things may be in cv2.cv module as well.
Second option is just to use this C++ code and call it from Python. Writing extensions for Python is not very easy, but if you use Boost.Python it shouldn't be very hard. Writing extension modules is quite popular task for Boost.Python so there are some good tutorials which describes that well. Good point to start might be this one. Writing converter for cv::Mat <->numpy.array might be a problem, but here is easy solution.
The key word you are looking for is "color transfer". I found this link really helpful http://www.pyimagesearch.com/2014/06/30/super-fast-color-transfer-images/
for Python install the color-transfer library like so;
pip install color_transfer
To use:
import color_transfer
destination_image = ... # import your destination image here
source_image = .... # import your source image here
new_image = color_transfer.color_transfer(source_image, destination_image)
Both source and destination images should be of type Numpy array.
From the script here I see how to set document keywords with the coreproperties function of python-docx. I want to look at the keywords already in a document written by someone else. Is there a getcoreproperties function or a keywords attribute or something similar?
I've grepped in folder C:\Python27\Lib\site-packages\python_docx-0.5.0-py2.7.egg\docx and none of the .py files there have the string "core" in them, and I've called doc() on a few things but without finding anything promising. Where/how should I look for clues to this kind of thing?
The python-docx library doesn't have support for core properties as of v0.5.0. But as it happens, that should be relatively easy to remedy.
The python-pptx sister project has support for core properties, as explained here:
http://python-pptx.readthedocs.org/en/latest/api/presentation.html#coreproperties-objects
Since the two projects are based on the same architecture, that code should be reusable essentially as-is. It turns out the core-properties bits are common to the the Open Packaging Convention, which is the same for all three of the MS Office XML file formats.
If you'll add an issue on the GitHub issue tracker I'll see how soon we can get to it.
https://github.com/python-openxml/python-docx/issues
I'm using python docx which claims in the documentation that:
'Often, a picture is placed in a paragraph by itself, but this is not required. It can have text before and after it in the paragraph in which it’s placed.'
But I cant find out how to do this, could someone explain (idealy with a basic example) how I get text before the image while in the same paragraph please. So the line of text ends with an image.
I've not found any answers to this but have seen people asking the same elsewhere with no solution.
Thanks
(note: I'm not a hugely experiance programmer and other than this awkward part the rest of my code will very basic)
At the time of this writing, python-docx doesn't have the features to support what you're trying to do.
The feature that would support it would be Run.add_picture(). If you add a feature request to the python-docx issue tracker, I'll see how soon we can get to it.
In the meantime, if you wanted to dig in and see what you could hack up, I'd recommend starting here, at Document.add_picture, as the structure would be analogous and use mostly the same calls.
If you just want to write docx files with Python, you can use another module:
https://github.com/rafaels88/py2docx
I'm aware I'm supposed to show some starting code to give you a clue as to what I'm trying to do, but I'm really at a basic level and I can't find any resources to show me what I'm after. Basically, I'm trying to write a plug-in for Sublime Text editor, which selects all div ID's then outputs them into a file. What's the best approach? It seems like it should be easy, but I'm not too sure.
Thanks in advance for your help,
Ewan
This looks like a good place to start: http://www.sublimetext.com/docs/plugin-basics
Look at http://www.sublimetext.com/docs/2/api_reference.html, though be advised that Sublime Text 3 is currently in beta. It introduces changes to the plugin api, and a requirement to support Python 3. See http://www.sublimetext.com/docs/3/porting_guide.html
Assuming you have some familiarity with python, I would start with this tutorial on for writing plugins (Link). The author of that tutorial wrote, among other things, package control. Granted, it is for ST2, but for what you are trying to do, I don't for see any major issues with writing a plugin that is compatible with both ST2 and ST3.
How you go about writing your particular plugin is up to you. One approach may be leveraging the view.find_all() method. This takes a regular expression and returns a set of regions. From these regions, you can grab the text, and subsequently the IDs for the divs. There may be a better way, but that might work as an initial attempt. Writing to a file can be done through the usual python means.